Menu function, MATLAB in Statistics

MENU Function:

The MATLAB also has a built-in function known as menu which will display a figure Window with push buttons for the choices. The very first string passed to the menu function is the heading, and the rest are labels which appear on the push buttons. The function returns the number of button which is pressed. For illustration,

>> mypick = menu('Pick a pizza', 'Shroom', 'Cheese', 'Sausage');

will display the Figure Window as shown in figure below and store the result of the user's button press in the variable mypick.

1482_menu function.png

There are three buttons, whose equivalent values are 1, 2, & 3. For illustration, if the user presses the Sausage button, then mypick would have the value 3:

>> mypick

mypick =

3

Note that the strings 'Shroom', 'Cheese', and 'Sausage' are merely labels on the buttons. The real value of the button press in this situation would be 1, 2, or 3.

A script which uses this menu function then would use either an if-else statement or a switch statement to take an action depends on the button pressed. For illustration, the script below simply prints which pizza to order, by using a switch statement.

236_menu function1.png

Here is an illustration of running this script and clicking the Sausage button:

>> pickpizza

Order a sausage pizza

Posted Date: 10/19/2012 3:27:54 AM | Location : United States







Related Discussions:- Menu function, Assignment Help, Ask Question on Menu function, Get Answer, Expert's Help, Menu function Discussions

Write discussion on Menu function
Your posts are moderated
Related Questions
Use of function polyval: The better the curve fit, the more exact these interpolated and extrapolated values will be. By using the subplot function, we can loop to display the

Example of Core objects: The one core graphics object is a line that is also what the plot function produces. Here is an illustration of generating a line object, altering som

Example of sorting strings: To sort a cell array of strings, also the sort function is used. The illustration is as follows, >> engcellnames = {'Chemical','Mechanical',.

Advanced File Input and Output: In that section, we saw how to read the values entered by user using the input as well as the output functions disp and fprintf, that shows inf

Opening and Closing a File: The Files are opened with the fopen function. By the default, fopen function opens a file for reading. If the other mode is preferred, a permission

Illustration of Binary search: An illustration to search for the key of 91 in the vector is as shown below: The table below shows what will happen in each iteration of

Variable packages: Variable packages are now the vector of structures, hence each and every element in the vector is a structure. To show one element in the vector, an index i

Illustration of Indexing: Though, rather than of creating the index vector manually as shown here, the process to initialize the index vector is use to a sort function. The al

Reading from Files: There are many lower level functions which read from files. The function fscanf reads the formatted data into a matrix, by using conversion formats like %s

Function polyval - interpolation: The function polyval can then be used to compute the polynomial at particular values. For illustration, we could compute at every value in th