17 - Script and Function Files and Managing Data - Full

17 - Script and Function Files and Managing Data - Full -...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style Engineering 101 Script/Function Files and Managing Data
Background image of page 1

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

View Full DocumentRight Arrow Icon
Quote of the Day - Confucius By nature, we are nearly alike; by practice, we get to be wide apart.
Background image of page 2
Script Files n A script file is created by typing your  command line inputs into a file and saving it  with a .m suffix ( multi_plots.m ) n Variables in a script file have global scope n Variables in a function file have local scope
Background image of page 3

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

View Full DocumentRight Arrow Icon
Output n display( )  is called when you don’t include a  semicolon after a MATLAB line where an  assignment occurs n disp(  data  )  will output only the data to the  screen.  Unlike  display( ) disp( )  does not put  a “data =“ message before the output. display_test. m
Background image of page 4
disp() n Example: x = [5 : 9]; disp(x); Output: 5 6 7 8 9
Background image of page 5

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

View Full DocumentRight Arrow Icon
disp() n Example: name = ‘Xena’; name2 = ‘:  Warrior Princess’; disp([‘My name is ’ name name2]); Output: My name is Xena:  Warrior Princess
Background image of page 6
     Which will output the following 3 rows of text? 00000000011111111112222222 12345678901234567890123456 abcdefghijklmnopqrstuvwxyz 1 2 3 4 S = char(X) converts  the array X that  contains nonnegative  integers representing  character codes into a  MATLAB character  array. 
Background image of page 7

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

View Full DocumentRight Arrow Icon
     Which will output the following 3 rows of text? 00000000011111111112222222 12345678901234567890123456 abcdefghijklmnopqrstuvwxyz 1 2 3 4 S = char(X) converts  the array X that  contains nonnegative  integers representing  character codes into a  MATLAB character  array.  Note:  Redefining  ones() is a really bad  idea…
Background image of page 8
Formatted output n Sometimes you want to specify the output  precisely.  The fprintf( ) command allows you to  specify a formatting string. n fprintf(format_string, variables)  will print the  values in the variables as specified in the  format_string. n Places for numbers in the format string are  specified like:  %-12.5e %{+,-,0}{field width}.{precision}{conversion}
Background image of page 9

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

View Full DocumentRight Arrow Icon
Formatted output n Conversion characters: n %csingle character n %d decimal number n %eexponential notation (lowercase e) n %E exponential notation (uppercase E) n %ffixed point notation n %sstring n %u decimal (unsigned)
Background image of page 10
Formatted output n Special characters in the format string n \t tab n \n new line n \\ backslash n \% percent
Background image of page 11

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

View Full DocumentRight Arrow Icon
fprintf() n Example: num = 1234.56789; fprintf(‘The number is %f !’,num); Output: The number is 1234.56789 !
Background image of page 12
fprintf() n Example: num = 1234.56789; fprintf(‘The number is %e !’,num); Output: The number is 1.2345678e+003 !
Background image of page 13

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

View Full DocumentRight Arrow Icon
fprintf() n Example: num = 1234.56789; fprintf(‘The number is %.1f !’,num); Output: The number is 1234.6 !
Background image of page 14
fprintf() n Example: num = 1234.56789; fprintf(‘The number is %08.1f !’,num); Output: The number is 001234.6 !
Background image of page 15

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

View Full DocumentRight Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/07/2010 for the course ENGR engr 101 taught by Professor Rinenberg during the Spring '10 term at University of Michigan.

Page1 / 63

17 - Script and Function Files and Managing Data - Full -...

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

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