CS 211 Lesson 25

Dialog Boxes

Quote:

Pain is temporary.  Quitting is forever.  Lance Armstrong

Lesson Objectives:

Lesson:

I. MATLAB Concepts

A. Dialog boxes

B. Modal vs. non-modal dialog boxes

C. Commonly used dialog boxes

MATLAB function

Description

Example Code and Resulting Dialog Box

msgbox display a message to the user;
by default, the dialog box is non-modal

msgbox('message','title')

msgbox('I like ice cream', 'FYI')

errordlg

displays an error message;
user must click ok to continue

errordlg('errorstring','dlgname')

errordlg('Invalid file name', 'File Error')

warndlg

displays a warning message;
user must click ok to continue

warndlg('warningstring','dlgname')

warndlg('Division by zero is undefined', 'Warning')

helpdlg

displays a help message;
user must click ok to continue
(always non-modal)

helpdlg('helpstring','dlgname')

helpdlg('Choose 3 pts from the figure', 'Point Selection')

inputdlg

prompts for one or more values and returns the corresponding user input

answer = inputdlg(prompt,dlgname,num_lines,defAns)

Coords = inputdlg({'x=', 'y='}, 'Enter coordinates:', 1, {'0','0'})

listdlg

allows a user to select one or more items from a list (always modal)

[Selection,ok] = listdlg('ListString',S,...)
All arguments come in 'PropertyName', 'PropertyValue' pairs. See MATLAB's help system for all possible properties.

[Selection OK] = listdlg('Name', 'Pick a color:', 'ListString', {'green', 'yellow', 'red'}, 'ListSize', [150, 50])

questdlg

asks a question with 2 or 3 possible answers (by default: yes, no, and cancel)

button = questdlg('qstring','title')

 

Answer = questdlg('Did you vote?', 'Vote Survey')

uigetfile

displays an OS's file selection dialog box; returns the selected file's name and directory path

[file_name folder] = uigetfile('FilterSpec','DialogTitle')

 

[Name Folder] = uigetfile('*.dat', 'Select input data file:')

uigetdir

displays an OS's directory selection dialog box; returns the selected file's directory path

folder_name = uigetdir('start_path','dialog_title')

 

Folder_name = uigetdir('C:\Documents and Settings', 'Select the desired folder')

uiputfile

displays an OS's file selection dialog box; warns if the user selects an existing file

[file_name folder] = uiputfile('FilterSpec','DialogTitle')

[Name Folder] = uiputfile('*.dat', 'Save file:');

printdlg

displays a printer dialog box (optionally in setup mode) for printing a figure

printdlg(figure)

plot(-pi:0.1:pi, cos(-pi:0.1:pi));
printdlg(figure(1))
or
printdlg('-setup', figure(1))

II. Good Programming Practices

III. Algorithms

Lab Work: Lab 25

References:  Chapman Textbook: section 10.6