files_lecture - Input/Output using Files October 15, 2007...

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

View Full Document Right Arrow Icon
Input/Output using Files October 15, 2007
Background image of page 1

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

View Full DocumentRight Arrow Icon
Reading and Writing to files Matlab provides many mechanisms for reading from and writing to files: load textread fopen, fclose, fid fread fwrite
Background image of page 2
LOAD Early in the term we used the LOAD command. LOAD can be used to: load a saved workspace, or load data from a .dat file into the workspace Using load to load data, creates a variable array containing all the data. Data must all be of the same type
Background image of page 3

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

View Full DocumentRight Arrow Icon
textread The textread function reads ASCII files that are formatted into columns of data, where each column may be of a different type Each column is stored as a separate output array VERY useful for incorporating tables of data textread is probably the most useful command for reading files when using Matlab for data analysis
Background image of page 4
textread (cont’d) Syntax: [a,b,c,. .]=textread(filename, format, n) filename is the name of the file to open format is a string containing a description of the type of data in each column format contains the same type of descriptors as the fprintf command n is the number of lines to read
Background image of page 5

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

View Full DocumentRight Arrow Icon
textread (cont’d) Suppose the our wind speed data also contained dates, times and directions: 010107 0000 15 SW 010107 0010 10 S We could read this into Matlab using the following command: [date,time,speed,direction]= … textread(‘WindData.dat’, ‘%s, %f, %f, %s’)
Background image of page 6
textread (cont’d) Suppose we now only wanted the
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.

This note was uploaded on 04/01/2008 for the course BEE 1510 taught by Professor Staff during the Winter '05 term at Cornell University (Engineering School).

Page1 / 21

files_lecture - Input/Output using Files October 15, 2007...

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