dialog boxes applications of cell arrays n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Dialog Boxes Applications of Cell Arrays PowerPoint Presentation
Download Presentation
Dialog Boxes Applications of Cell Arrays

Loading in 2 Seconds...

play fullscreen
1 / 40

Dialog Boxes Applications of Cell Arrays - PowerPoint PPT Presentation


  • 149 Views
  • Uploaded on

Dialog Boxes Applications of Cell Arrays. Reminder of Symbols Dialog Boxes Output-centric dialogs Input-centric dialogs. 1. Reminders on Symbols. Creating/hard-coding: Braces { } Referencing content: Braces { } Augmenting: Brackets [ ] Referencing container : Parentheses ().

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Dialog Boxes Applications of Cell Arrays' - dana


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
dialog boxes applications of cell arrays
Dialog BoxesApplications of Cell Arrays

Reminder of Symbols

Dialog Boxes

Output-centric dialogs

Input-centric dialogs

1 reminders on symbols
1. Reminders on Symbols
  • Creating/hard-coding: Braces { }
  • Referencing content: Braces { }
  • Augmenting: Brackets [ ]
  • Referencing container: Parentheses ()
2 dialog boxes1
2. Dialog Boxes
  • Dialog boxes are "popup windows" that allows us another means to communicate with the user.
  • Some dialog boxes to collect input:

inputdlg(), listdlg(), menu(), questdlg()

  • And some to produce output:

msgbox(), helpdlg(), warndlg(), errordlg()

output centric dialog boxes
Output-centric Dialog Boxes

Output-centric dialog boxes are popup windows with the primary purpose of providing information to the user.

Examples are: msgbox(), helpdlg(), warndlg(), and errordlg()

output centric dialog boxes1
Output-centric Dialog Boxes

Output-centric dialogs are "non-blocking" – they do NOT (on their own) prevent the rest of the program from executing. They can, however be created as "modal". A modal dialog prevents the user from interacting with other windows until it is closedbut does not interfere with the execution of the program.

output centric dialog boxes2
Output-centric Dialog Boxes

Output-centric dialogs are "non-blocking" – they do NOT (on their own) prevent the rest of the program from executing. They can, however be created as "modal". A modal dialog prevents the user from interacting with other windows until it is closedbut does not interfere with the execution of the program.

You may wish to create a blocking output-centric box. This is accomplished by collecting the return value of the dialog box function call and then using either the waitfor()or uiwait()function:

wh= msgbox('Here is some information.', 'Special Info!');

waitfor(wh);

output centric dialog boxes3
Output-centric Dialog Boxes

Output-centric dialogs are "non-blocking" – they do NOT (on their own) prevent the rest of the program from executing. They can, however be created as "modal". A modal dialog prevents the user from interacting with other windows until it is closedbut does not interfere with the execution of the program.

You may wish to create a blocking output-centric box. This is accomplished by collecting the return value of the dialog box function call and then using either the waitfor()or uiwait()function:

wh= msgbox('Here is some information.', 'Special Info!');

waitfor(wh);

uiwait() provides a programmatic as well as a user-based means to continue. Use uiresume()to continue.

msgbox helpdlg warndlg errordlg
msgbox(), helpdlg(), warndlg(), errordlg()

Each creates a dialog box that will output a string

% calculate/display

travelTime = distance/speeds(type);

resultString = sprintf('With this plane, it will take %.2fhrs.\n', travelTime);

msgbox(resultString)

msgbox
msgbox()
  • Use sprintf() customize the data in the message box
    • Creates a formatted string

%calculate/display

travelTime = distance/speeds(type);

resultString = sprintf('With a %s, it will take %.2fhrs.\n', myPlanes{type}, travelTime);

msgbox(resultString)

msgbox1
msgbox()
  • Use sprintf() customize the data in the message box
    • Creates a formatted string

%calculate/display

travelTime = distance/speeds(type);

resultString = sprintf('With a %s, it will take %.2fhrs.\n', myPlanes{type}, travelTime);

wh = msgbox(resultString);

waitfor(wh);

input centric dialog boxes
Input-centric Dialog Boxes

Input-centric dialog boxes are those boxes which are intended to have the user provide information.

Input-centric dialogs are "blocking" – which is sometimes incorrectly referred to as "modal".

A modal dialog prevents the user from interacting with other windows until it is closed. A blocking dialog prevents the rest of the program from executing until it is closed.

3 inputdlg
3.inputdlg()
  • Collects information from the user
  • inputdlg() – much like the input() function, except…
    • It is presented in a pop-up window form
    • There can be multiple prompts and multiple values provided by the user.
  • ALL user-provided information is returned as stringsin a cell array!
inputdlg syntax
inputdlg(), syntax

var = inputdlg(prompts);

  • Arguments
    • A cell array of strings: This is the set of prompts for the user. For example:

prompts={'Prompt 1', 'Prompt 2', 'Prompt N'}

  • Return Values
    • One (1) cell array of strings: What the user provided in the boxes
  • Example

prompts={'Coeff "a":', 'Coeff "b":', 'Coeff "c":'};

coeffs = inputdlg(prompts);

cell array, indicated by the curly braces.

inputdlg output
inputdlg(), output
  • Whencollectingnumbers, use str2double() to convert the cellarrayinto a numericalvector:

coeffs = str2double(coeffs);

15

4 listdlg
4. listdlg()
  • listdlg() – Create and open list-selection dialog box
    • User does not have to type anything: Prevent typing errors!
listdlg calling syntax
listdlg()calling-syntax

[Selection, ok] = listdlg(<param name>, <param value>)

This function returns 2 values.

  • Selection is a vector of indices of the selected strings
  • Ok is a recognition of user selection
    • 1if user clicks the OK button
    • 0if clicks click the Cancel button or close the dialog box (X)
listdlg calling syntax1
listdlg()calling-syntax

[Selection, ok] = listdlg(<param name>, <param value>)

There are many parameters available to the listdlg() function, so the calling syntax is a bit different.

listdlg calling syntax2
listdlg() calling-syntax

[Selection, ok] = listdlg(<param name>, <param value>)

There are many parameters available to the listdlg() function, so the calling syntax is a bit different.

listdlg calling syntax3
listdlg()calling-syntax

[Selection, ok] = listdlg(<param name>, <param value>)

There are many parameters available to the listdlg() function, so the calling syntax is a bit different.

Instead of relying on the order of the arguments, the programmer provides both the name of a parameter and the argument value for that parameter.

In all cases, the 'ListString' parameter must be provided. This parameter is a cell array of strings containing the options that will be provided to the user.

listdlg syntax
listdlg()- syntax

[Selection, ok] = listdlg('ListString', S)

  • Arguments are in parameter/valuepairs
    • Parameter goes 1st, value of the parameter goes 2nd.
  • 'ListString' – Cell array of strings that specify list

S = {'Item 1', 'Item 2', 'Item N'}

sample use of listdlg
Sample use of listdlg()

myList is a cell array of strings: { }

Why cell arrays?

The length of each selection varies widely, and a regular array would not be rectangular.

listdlg calling syntax4
listdlg() calling syntax

S = {'My choice', 'Your choice', 'His choice', 'Her choice'}

[Selection, ok] = listdlg('ListString', S)

'SelectionMode' - 'single' or 'multiple'

'Name' – Title string

'ListSize' – Vector of width and height in pixels

'PromptString' – String or cell array

'OKString' – String for OK button

'CancelString' – String for Cancel button

[Selection, ok] = listdlg('ListString', S, …

'SelectionMode', 'single', 'ListSize', [160, 160])

listdlg question
listdlg() - Question
  • If the user selects Primary Booster and Secondary Booster, What will Selection- the first return value - be after this executes?
  • {'Primary Booster','Secondary Boosters'}
  • [1 3]
  • {1, 3}
  • None of the above
experiment in the command window
Experiment in the command window!
  • What button did the user hit?
  • The 'ok' button
  • The 'cancel' button
  • The Xthat closes the window
  • Either b or c
  • None of the above
listdlg syntax1
listdlg()- syntax

[Selection, ok] = listdlg('ListString', S, …

'SelectionMode', 'Single')

  • SelectionMode - A second argument parameter/valuepair
    • Allows user to select a SingleorMultiple(default) items
2nd pair of arguments
2nd PAIR of arguments

The Select All button is gone.

2nd pair of arguments1
2nd PAIR of arguments
  • What item did the user select?
example aircraft time
Example: Aircraft Time
  • Create a program that estimates the time an aircraft takes to travel a certain distance.

Aircrafts possible, with their average speeds are:

    • Cessna 150, 198 kmph
    • Boeing 787, 950 kmph
    • Concorde, 2147 kmph
    • Cessna 421, 444 kmph
algorithm
Algorithm

% prompt user for type of airplane (error?)

% prompt user for distance to travel (error?)

% calculate/display

  • Presented is the evolution from:
    • Option1: use input() and if.
    • Option2: use input() and vectors.
    • Option3: using listdlg(), vectors and cell arrays.
option 1 input if and while
Option #1. input(), if and while

%prompt user for type of airplane

type = input('Enter the type of airplane: \n1 – cessna 150\n 2-Boeing 787\n3-Concorde\n4-Cessna 421\n Enter now: ');

%prompt user for distance to travel

distance = input('Enter the distance (km): ');

%calculate/display

if type == 1 %cessna 150

travelTime = distance/198;

fprintf('With this plane, it will take %.2fhrs.\n', travelTime);

elseif….

Add while loops to trap errors.

option 2 input vectors while
Option #2. input(), vectors, while

%prompt user for type of airplane

type = input('Enter the type of airplane: \n1 – cessna 150\n 2-Boeing 787\n3-Concorde\n4-Cessna 421\n Enter now: ');

%prompt user for distance to travel

distance = input('Enter the distance (km): ');

%data base of speeds

speeds = [198, 950, 2147, 444];

%calculate/display

travelTime = distance/speeds(type);

fprintf('With this plane, it will take %.2fhrs.\n', travelTime);

Add while loops to trap errors.

Reference the correct value in the vector, using the index.

option 3 listdlg arrays while
Option #3. listdlg(), arrays, while

%prompt user for type of airplane

myPlanes = {'Cessna 150', 'Boeing 787', 'Concorde', 'Cessna 421'};

type = listdlg('ListString', myPlanes,'SelectionMode', 'Single');

%prompt user for distance to travel

distance = inputdlg('Enter the distance (km): ');

%data base of speeds

speeds = [198, 950, 2147, 444];

%calculate/display

travelTime = distance/speeds(type);

fprintf('With this plane, it will take %.2fhrs.\n', travelTime);

Add while loop to trap errors, and convert to number

option 3 sample
Option #3. Sample
  • Note: once a programstarts with dialog boxes, it should use only dialog boxes…

>> not the command window

menus
Menus
  • menu()
    • Provides the user with a vertical list of buttons to select (No limit)
    • Returns the index of the button selected
    • How do we work with this?

Options = {'Cheese', 'Water', 'Cake', 'Pie', 'Oranges'};

Choice = menu('Here are the dessert options. What would you like?', Options)

menus1
Menus
  • questdlg()
    • Offers the user a maximum of three push buttons to select options
    • Returns the actual string used in the selected button
  • menu()
    • Provides the user with a vertical list of buttons to select (No limit)
    • Returns the index of the button selected
file and directory selection
File and Directory Selection

To have the user choose a file:

filename = uigetfile(FilterSpec)

Where FilterSpec is a:

- column vector cell array of file extension patterns

{'*.txt'; '*.dat'; '*.csv'}

fname = uigetfile({'*.dat';'*.txt'; '*.csv'})

file and directory selection1
File and Directory Selection

To have the user choose a file:

filename = uigetfile(FilterSpec)

Where FilterSpec is a:

- two-column matrix cell array of file extension patterns and descriptive text

{ '*.txt', 'Text files (.txt)';

'*.dat', 'Data files (.dat),

'*.csv', 'Comma-separated files (.csv)'

}

fname = uigetfile({'*.dat', 'Data files (.dat)'; '*.txt', 'Text files (.txt)'; '*.csv', 'Comma-separated (.csv)'})

file and directory selection2
File and Directory Selection

To have the user choose a directory (folder):

folderPath = uigetdir(startPath)

Where startPath is a string with the entire path to the folder, and folderPath is a string with the entire path to the selected folder.

folder = uigetdir('c:\windows\system32')

(MATLAB on Windows can use forward slashes as folder separators)

NOTE: The special path designators '.' and '..' can also be used in the path:

'.' The current directory

'..' The parent directory

more information
More Information

Mathworks: Pre-defined Dialog Boxes

http://tiny.egr115.com/?id=47

http://www.mathworks.com/help/matlab/predefined-dialog-boxes.html