Convert fig into csv, txt or ascii

82 views (last 30 days)
tori613
tori613 on 8 Sep 2015
Commented: tori613 on 9 Sep 2015
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

Adam
Adam on 8 Sep 2015
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
Walter Roberson
Walter Roberson on 9 Sep 2015
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,:)));
tori613
tori613 on 9 Sep 2015
csvwrite works perfectly now, thank you everyone!

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!