Lab 11: Create a survey

Step 0: Getting started

Download the lab11 folder, which contains a file named QuestionsAndAnswers.txt. Open it to examine its formatting. It contains quadrubles of lines:

  Question, followed by three answers, each one in its own line.

Step 1: Create your GUI layout in App Designer

Open App Designer and create the visual layout for your GUI in the Design View, with four GUI components: Try to create something like this:

When saving your App for the first time, be sure to save it in your survey folder.

You're welcome to arrange the components as you'd like, for example:

Step 3: Create new properties to store survey information

Create three new properties to store the following information:

Step 4: Create a startupFcn callback function

An App has a startup function that you can define, which is executed automatically when the App starts up. For this program, you'll create a startup function to read the contents of your text file into the property you just created to store this information. To do this, follow these steps:

Step 5: Create a callback function for the quit button

As you've done in previous Apps, add a callback function that terminates the program when you push the quit button.

Step 6: Add a callback function to control the flow of the survey

A single button, such as the one labeled start survey in the above GUI (we'll refer to this as the "survey button"), together with the current question number, can be used to control the flow of the survey. In Step 3 above, a new property was created to store the current question number. The question number was initialized to 0, indicating that the survey has not yet begun. As the user progresses through the survey, the question number can be incremented to 1, then to 2, and finally to 3, signifying the end of the survey and time to display the results. The progression through these steps will be controlled by the user pushing the survey button — each time the user pushes this button, the question number will be increased and appropriate actions performed.

Add a ButtonPushedFcn callback function for the survey button. The main tasks to be performed by this callback function are:

  1. record the user's answer to the current survey question (once the survey begins)
  2. update the question number for the survey
  3. if there are still more questions to ask, then update the GUI display with the next question and answer options; otherwise show the results of the survey on the GUI

Note that when the survey button is pushed, the question number will have the value 0, 1, or 2.

In more detail, this callback function should perform the following actions:

(1) if the current question number is 1 or 2:

(2) increment the question number

(3a) if the new question number is 1 or 2:

(3b) otherwise (i.e., the new question number is 3):

The following snapshots show one progression through the demonstration program, after the user pushes the start survey button (we're not sure why MATLAB sometimes displays a horizontal gap in the radio button text):