Download presentation
Presentation is loading. Please wait.
Published byEmery Curtis Modified over 9 years ago
1
File Operations in Matlab Load / Save *.dat, *.mat vs. -ascii fopen /fclose
2
Load and Save 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
3
-ascii option 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 >>
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 >> fid = fopen('x.mat', 'w+'); >> load x.txt >> fprintf(3, ' %6.4f\n ', x); >> fid fid = 3 >> fclose(fid); >>
5
results x.txtx.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 1.accepts structure array 2.plots the info in the array section 7.3.4-5 (p. 310 -311)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.