user_input_output

user_input_output - User Input and Output Greg Reese, Ph.D...

Info iconThis preview shows pages 1–17. Sign up to view the full content.

View Full Document Right Arrow Icon
User Input and Output Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University
Background image of page 1

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

View Full DocumentRight Arrow Icon
User Input and Output © 2010 Greg Reese. All rights reserved 2
Background image of page 2
Terminology GUI: Graphical User Interface I/O: Input or Output Two ways to do user I/O, i.e., get input from the user or show output to the user) 1. In the command-line window 2. Using a GUI User I/O 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Command line advantages Easy Can use if MATLAB graphics not available Automatically converts text input to number Command-line I/O 4
Background image of page 4
Use MATLAB function input entry = input( prompt ) displays prompt as a prompt on the screen, waits for input from the keyboard, and returns the value entered in entry evaluated using variables in workspace if user just presses ENTER key, entry is an empty matrix Command-line input 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example >> a = [ 4 5 6 ]; >> entry = input( 'Index into a: ' ); Index into a: 2 >> a(entry) ans = 5 >> entry = input( 'Expression with a: ' ) Expression with a: a(2)+5 entry = 10 Command-line input 6
Background image of page 6
Example – typical use Ask user for information >> weight = input( 'Weight in kg: ' ); Weight in kg: 37.4 >> weight weight = 37.4000 Command-line input 7
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example Typical use with default value >> reply = . .. input('Do you want more? Y/N [Y]: ' ); >> if isempty(reply) reply = 'Y'; end Command-line input 8 Common convention is to show default value in brackets [] or parentheses ()
Background image of page 8
Try it Ask the user for a plane’s altitude in feet and display the result >> altitude=input('Altitude in feet: ') Altitude in feet: 10000 altitude = 10000 Command-line input 9
Background image of page 9

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

View Full DocumentRight Arrow Icon
entry = input( prompt, 's' ) Forces return to be a text string Command-line input 10
Background image of page 10
Example >> altitude = input( 'Altitude in feet: ' ) Altitude in feet: 10000 altitude = 10000 >> whos altitude Name Size Bytes Class Attributes altitude 1x1 8 double >> altitude = input( 'Altitude in feet: ', 's' ) Altitude in feet: 10000 altitude = 10000 >> whos altitude Name Size Bytes Class Attributes altitude 1x5 10 char Command-line input 11
Background image of page 11

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

View Full DocumentRight Arrow Icon
12 Command-line Input Questions?
Background image of page 12
Easiest is to omit semicolon at end Good for debugging No control over format >> a a = 4 5 6 Command-line output 13
Background image of page 13

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

View Full DocumentRight Arrow Icon
Second easiest is MATLAB disp() command disp( X ) displays an array or text string X without showing the array’s name Convenient Very limited formatting Won’t display empty array Command-line output 14
Background image of page 14
Example >> population = round( 1000*rand(4,2) ) >> label = 'Indiana Ohio'; >> disp( label ), disp( population ) Indiana Ohio 815 632 906 98 127 278 913 547 >> disp( [] ) >> Command-line output 15
Background image of page 15

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

View Full DocumentRight Arrow Icon
Can specify total number of characters precision (numbers after decimal place) padding with zeros or other characters Will look at in detail later. For now. .. Command-line output
Background image of page 16
Image of page 17
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/04/2011 for the course MME 414 at Miami University.

Page1 / 52

user_input_output - User Input and Output Greg Reese, Ph.D...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online