File and Directory Management

File and Directory Management - Chapter 5 File and...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Chapter 5 File and Directory Management 5.1 The MATLAB Workspace User commands and resulting output in the MATLAB Command window can be logged and saved as an ascii text file in the current folder. The ' diary fname ' command keeps a log of the MATLAB session and stores it in the file ' fname ' or simply ' diary ' if the file name is ommitted. Example 5.1.1 diary klee_sept6 % Save MATLAB session in file klee_sept6 x=1; y=2; z=x+y A=5 B=10 C=A*B diary off z = 3 A = 5 B = 10 C = 50 The entire Command window or a highlighted portion of it can be printed using either Print or Print Selection from the Command window File menu. All variables and their values present in the MATLAB Workspace at the end of a MATLAB session can be saved using Save Workspace as ... from the File menu of the Command window. To load the same variables and their stored values in the MATLAB Workspace, the Load Workspace ... menu item from the File menu is used. 1 5.2 Saving, Loading, and Deleting Files Specific variables from the MATLAB Workspace can be saved in a choice of formats using the ' save ' command. Example 5.2.1 clear price =2.5; volume=2000; revenue=price*volume; save % Saves Workspace variables in binary format in file 'matlab.mat' Saving to: matlab.mat clear rate =5.0; time=1000; dist=rate*time; save trip % Saves Workspace variables in binary format in 'trip.mat' clear rad=3; Area=pi*rad^2; circum=2*pi*rad; save circle Area circum % Saves Workspace variables 'A' and 'circum' % in binary format in file 'circle.mat' clear l=8; w=4; h=3; A=l*w; V=A*h; save box l w h -ascii % Saves Workspace variables 'l', 'w', and 'h' % in 8-digit ascii format in file 'box' Note that the ascii files are not assigned a .mat extension. Selected variables from saved .mat files can be loaded into the MATLAB Workspace using the ' load ' command. Example 5.2.2 clear load % Loads all variables from file 'matlab.mat into MATLAB Workspace Loading from: matlab.mat clear load circle Area circum % Loads variables 'Area' and 'circum' from % file 'circle.mat' into MATLAB Workspace The following command is invalid because an ascii file cannot be loaded into the MATLAB Workspace. It can only be edited in a text editor. 2 load box l w % Loads variables 'l' and 'w' from ascii file 'box' To see if a particular data file has been saved in the current directory (or on MATLAB's search path) the 'exist' command is issued and returns a value of 2, otherwise a zero is returned. Example 5.2.3 clear x=0.25 sum=1/(1-x) % Sum of geometric series 1 + x + x^2 + x^3 + ... save geoseries % Save Workspace variables in file 'geoseries.mat' exist('geomseries.mat','file')% Check for existence of 'geomseries.mat' exist('geoseries.mat','file') % Check for existence of 'geoseries.mat' x = 0.2500 sum = 1.3333 ans = ans = 2 The variables stored in a MATLAB data file (.mat extension) can be obtained from the Command window using the ' whos ' command along with the file name....
View Full Document

This note was uploaded on 06/09/2011 for the course EGM 4320 taught by Professor Klee during the Spring '11 term at University of Central Florida.

Page1 / 20

File and Directory Management - Chapter 5 File and...

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

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