MATLAB File Operation Summary
MATLAB #Dataprocessing
In doing research,We often need output the result to the file and read from the file.In this note, I will summarize the methods of reading and output method in MATLAB.
Deirectly read and write
mat file
We first consider the method of saving and read the MATLAB type file. The Matrix in MATLAB can be directly saved in a “xx.mat” file. This method can save many different result in an whole single file. I really recommend this method. This can be done as follows:
1 | filename=['sweep_result_',datestr(now,'yyyy_mm_dd_HHMMSS'),'.mat']; |
to read the file,
1 | load('filename') |
csv,txt file
the mat file can only be opened in MATLAB, In order to allow other software to open the output file. We can save the file as txt or csv file. This can be done via csvread/cavwrite, textread/textwrite,dlmwrite/dlmread,And I recommend the dlm method
1 | % read csv file via "csvread" |
fopen method
this can be done via fopen and fprintf method
1 | fid=fopen('progress.txt','at'); |
“print” output image to file
to save the figure in the window,the best way is to use print.
1 | filename=['xxxxx_','.png']; |