{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecturenotes9_12

lecturenotes9_12 - UserInput p Output...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
9/11/2008 1 Command Window Input and Output Friday September 12, 2008 User Input Input Statement Syntax: >> varname = input(‘Instructions to user’); From wind power example: Wi dS d i (‘Pl h i d d >> WindSpeed = input(‘Please enter the wind speed in m/s.’) This prints the text in quotes to the command window and awaits user input The value that the user enters is now assigned to the variable name given in the input statement. Input Statement Options We can also have the user enter matrices: >> x = input(‘Enter the values for the matrix in brackets.’) Use can now enter [1 2 3, 4 5 6] and now… = 6 5 4 3 2 1 x And strings… The user can also enter a string. >> x = input(‘Input your name.’) will not work (it will only take the first value, as it reads the string as a sequence of scalars. The correct way to do this is: >> x = input(‘Input your name in quotes.’) ‘joe’ OR >> x = input(‘Input your name.’, s) tells matlab to expect a string as input
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon