files_lecture - Input/Output using Files Reading and...

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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’)
Image of page 6
textread (cont’d)
Image of page 7

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern