Tuesday, May 8, 2012

matlab read and write to file


how to write data into a file 
_________________________________
csvwrite('attr20.ascii',A); 
 csvwrite(filename,M)
csvwrite(filename,M,row,col) 

--------------------
dlmwrite(filename, M)
dlmwrite(filename, M, 'D')
dlmwrite(filename, M, 'D', R, C)
 
dlmwrite('myfile.txt', M, 'delimiter', '\t', ...
         'precision', 6)
type myfile.txt
0.893898      0.284409      0.582792      0.432907
0.199138      0.469224      0.423496      0.22595
0.298723      0.0647811     0.515512      0.579807
0.661443      0.988335      0.333951      0.760365

http://www.mathworks.in/help/techdoc/ref/dlmwrite.html


 
 http://www.myoutsourcedbrain.com/2008/11/export-data-from-matlab.html
http://www.mathworks.com/matlabcentral/newsreader/view_thread/314766 
 
 http://www.mathworks.com/matlabcentral/newsreader/view_thread/314766
 
 
 
 
-------------------------------- 

Write dataset array to file

Syntax

export(DS,'file',filename)
export(DS)
export(DS,'file',filename,'Delimiter',delim)



 
 
 read to file 
M = csvread(filename)
M = csvread(filename, row, col)
http://www.mathworks.in/help/techdoc/ref/csvread.html 

more info type 'csvread' in matlab help 
-------------------------  
 
 
A = fread(fileID)
A = fread(fileID, sizeA)
 ---------------
 
[A,B,C,...] = textread(filename,format)  
 
------------- 
http://www.mathworks.in/help/matlab/import_export/supported-file-formats.html 

------
http://ocw.mit.edu/resources/res-18-002-introduction-to-matlab-spring-2008/other-matlab-resources-at-mit/tutorial05.pdf



FOR LOOP
http://www.cyclismo.org/tutorial/matlab/control.html
http://www.math.utah.edu/~wright/misc/matlab/programmingintro.html
http://www.cs.utah.edu/~germain/PPS/Topics/Matlab/plot.html


sub plot 
subplot(1,2,1), imshow('autumn.tif');
subplot(1,2,2), imshow('glass.png');
 
Function 
 
function [out1, out2, ...] = myfun(in1,in2, ...) 
 
Example
 
function [mean,stdev] = stat(x)
n = length(x);
mean = sum(x)/n;
stdev = sqrt(sum((x-mean).^2/n));

No comments:

Post a Comment