04_basics-p2 - MATLAB Basics Part II ENCMP 100 Overview...

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

View Full Document Right Arrow Icon
MATLAB Basics – Part II
Background image of page 1

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

View Full DocumentRight Arrow Icon
ENCMP 100 2 ©2011 by ECE, UofA Overview Simple file I/O commands Built-in functions Arithmetic operators Creation of variables Debugging Sub-arrays and multi-dimensional arrays MATLAB Basics II
Background image of page 2
ENCMP 100 3 ©2011 by ECE, UofA We will learn how MATLAB handles data files because very often we need to load or save data in programming. Special data file format in MATLAB: the MAT file .mat file is the default type that data files are saved in MATLAB. We will need MATLAB to process .mat file. To share data among different programs, we need to specify the –ascii option when saving or loading the data Basic data file functions: save load MATLAB Basics II Basic input/output (I/O) functions
Background image of page 3

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

View Full DocumentRight Arrow Icon
ENCMP 100 4 ©2011 by ECE, UofA The ` save() function: It saves data from the current MATLAB workspace to a file. A general form: save(‘file_name’, ‘var1’, ‘var2’) It saves one or more variables (e.g. var1, var2,… ) in a file with the name specified by the file_name string (a string containing the file name and/or the path) . By default, the file name will be given a MAT file extension .mat if it has no other extension specified. To save in the more general ascii data format, use save(‘file_name.dat’,‘var’,‘-ascii’) It is suggested to add the .dat extension to the file name in this case to differentiate from the .mat file. Use single quotation marks because the arguments are strings! Basic data file processing functions MATLAB Basics II
Background image of page 4
ENCMP 100 5 ©2011 by ECE, UofA The save function can also be executed in a command form, save file_name var1 var2 or save file_name.dat var1 var2 -ascii Different from the save() function, there are no single quotation marks for the file name and the variable in this command form. They are simply separated by space. Therefore, in the case when the file name contains one or more spaces, this command form cannot be used, e.g. save my file x y z ( wrong! It’ll treat file as one variable to be saved ) save my_file x y z ( correct!) or write save(‘my file’, ‘x’, ‘y’, ‘z’) (correct!) Basic data file processing functions MATLAB Basics II
Background image of page 5

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

View Full DocumentRight Arrow Icon
ENCMP 100 6 ©2011 by ECE, UofA The ` load() function: It loads data from a disk file to the current MATLAB workspace. A general format is shown below: load(‘file_name’) It loads all variables saved (e.g. var1, var2, var3 ) in the file with the name specified by the file_name string. If the file name has no extension, by default MATLAB will treat it as a MAT file. It is also possible to load specified variables in the file: load(‘file_name’, ‘var1’, ‘var2’) To load an ASCII data file, use: load(‘file_name.dat’) Use –mat or –ascii options: load(‘myfile.dat’, ‘-mat’) load (‘myfile.mat’, ‘-ascii’) Basic data file processing functions MATLAB Basics II
Background image of page 6
ENCMP 100 7 ©2011 by ECE, UofA Just like save function, the load function has a command form : load format file_name var1 var2 . .
Background image of page 7

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

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

Page1 / 56

04_basics-p2 - MATLAB Basics Part II ENCMP 100 Overview...

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

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