File Operations in Matlab - PowerPoint PPT Presentation

About This Presentation
Title:

File Operations in Matlab

Description:

File Operations in Matlab Load / Save *.dat, *.mat vs. -ascii fopen /fclose Load and Save Get data from other applications Save variables for later use x = 1:10 x ... – PowerPoint PPT presentation

Number of Views:69
Avg rating:3.0/5.0
Slides: 9
Provided by: bing89
Category:

less

Transcript and Presenter's Notes

Title: File Operations in Matlab


1
File Operations in Matlab
  • Load / Save
  • .dat, .mat vs. -ascii
  • fopen /fclose

2
Load and Save
  • gtgt x 110
  • x
  • 1 2 3 4 5 6 7 8
    9 10
  • gtgt y x . 2
  • y
  • 1 4 9 16 25 36 49 64
    81 100
  • gtgt save x.mat x y
  • gtgt load x.mat
  • Get data from other applications
  • Save variables for later use

3
-ascii option
  • Save variable data into file with standard
    character format
  • Open or import into spreadsheets, database, word
    processor
  • gtgt x
  • x
  • 1 2 3 4 5 6 7 8
    9 10
  • gtgt y
  • y
  • 1 4 9 16 25 36 49 64
    81 100
  • gtgt save x.txt x y -ascii
  • gtgt

4
fopen / fclose
  • Open files and write or read data into them.
  • Use the file ID to specfiy placement of data.
  • fprintf writes formatted data to files
  • gtgt fid fopen('x.mat', 'w')
  • gtgt load x.txt
  • gtgt fprintf(3, ' 6.4f\n ', x)
  • gtgt fid
  • fid
  • 3
  • gtgt fclose(fid)
  • gtgt

5
results
x.txt
x.mat
6
Hints
  • 5.18 Use example 4.7 (p.166)
  • Turn this into a function
  • function slope, y_int lsqfit(x,y)
  • Functions section 5.1 (p. 190)

7
Hints
  • 5.22
  • Use rand function to generate random number.
  • Scale from 0,1) interval to -1,1)
  • Make user-defined function to transform uniform
    to normal
  • use this function in m-file to generate array
  • use hist() function, and std() built in functions

8
Hints
  • 7.6 structure arrays
  • Define structure array in m-file
  • Create user defined function that
  • accepts structure array
  • plots the info in the array
  • section 7.3.4-5 (p. 310 -311)
Write a Comment
User Comments (0)
About PowerShow.com