Download presentation
Presentation is loading. Please wait.
Published bySibyl Blankenship Modified over 9 years ago
2
S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: User Input / Output Programming Environment
3
MATLAB Programming: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Input / Output 2 Other Useful Functions n Input Input n Pause Pause n Echo Echo n Menu Menu
4
MATLAB Programming: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Input / Output 3 Input Function - Number input command prompts the user for an input » n=input('Please enter a positive integer: ') Please enter a positive integer: 23 n = 23 n Matlab waits until the user types an input and then presses the return key
5
MATLAB Programming: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Input / Output 4 Input Function - String n Input command asks the user for a string n Matlab waits until the user types a string and then presses the return key » name=input( 'Please enter your name: ', 's' ) Please enter your name: Awad name = Awad
6
MATLAB Programming: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Input / Output 5 Pause Command The pause command allows the user to suspend the execution of commands until any keyboard key is pressed n No Input Argument Example: Type the following into an M-Script, then execute a=2;% Line 1 b=3;% Line 2 c=a+b;% Line 3 pause;% Wait d=c*c;% Continue n Matlab will pause after executing 3 lines. It will resume executing after the user presses any key pause(n) will pause n seconds
7
MATLAB Programming: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Input / Output 6 Echo Command The echo command controls the command window echoing of script file commands » test Matlab Results c = 5 a=2;% Normally hide b=3;% Normally hide c=a+b% Show result Create the following test.m M-Script » echo Toggles Echo ON » test a=2;% Normally hide b=3;% Normally hide c=a+b% Show result c = 5 » echo Toggles Echo OFF
8
MATLAB Programming: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Input / Output 7 » k=menu('Choose a color','r','b','g') Menu Command The menu command generates a menu of choices for the user to input Press b k = 2
9
MATLAB Programming: U of M-Dearborn ECE Department Introduction to MATLAB and its Toolboxes Input / Output 8 Use of Menu Results n k = 2 (blue) from previous slide n This information can be used for plotting » color=['r' 'b' 'g']; » x=[0:10];y=2*x; » plot(x,y,color(k)); » title('Plot color from Menu' );
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.