1 / 8

File Operations in Matlab

File Operations in Matlab. Load / Save *.dat, *.mat vs. -ascii fopen /fclose. Get data from other applications Save variables for later use. >> x = 1:10 x = 1 2 3 4 5 6 7 8 9 10 >> y = x .^ 2 y =

lillianvega
Download Presentation

File Operations in Matlab

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

  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)

More Related