Convert fig into csv, txt or ascii

I have the m-file on generating all the graphs in .fig I need with a for loop, but I don't know how to extract the array data to csv, txt or ascii format (16-bit).
imagesc(x,y,C); %C is the data I want to extract
%m and n are variables created inside the for loop
I have tried dlmwrite and save, but I failed and could not fix the problem.
So I want to convert fig into csv, txt or ascii format instead.
filename_B=strcat(MM,'_profile'); %MM is a variable created inside the for loop
dlmwrite(filename_B.txt,squeeze(Data_time(:,m,n,:)),''); %Data_time is C
save(filename_B, squeeze(Data_time(:,m,n,:)),'-ascii','-double');
It would be better if I could just extract the data directly to the desirable format without first producing fig then convert.
For confidential issue, I can't provide the whole script, but I will try my best to explain my problem.
Many thanks!

 Accepted Answer

I've never used it myself but there is a
doc csvwrite
function that sounds like it does what you want with respect to writing to csv.
doc fprintf
will write to a text file too if you specify it correctly.

3 Comments

thank you!
I have just tried csvwrite, and here's the problem...
csvwrite(filename_B, squeeze(Data_time(:,m,n,:)));
%all the output files are saved as an unknown file type,
%and the for loop works perfectly,
%but unknown file type is useless
csvwrite(filename_B.txt, squeeze(Data_time(:,m,n,:)));
%after I added the file extension (.txt),
%there is an error message,
%Attempt to reference field of non-structure array.
I don't understand the error message, so I can't fix it.
csvwrite('filename_B.txt', squeeze(Data_time(:,m,n,:)));
or if filenme_B is a string,
csvwrite([filename_B '.txt'], squeeze(Data_time(:,m,n,:)));
csvwrite works perfectly now, thank you everyone!

Sign in to comment.

More Answers (0)

Asked:

on 8 Sep 2015

Commented:

on 9 Sep 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!