How to save all .fig outputs in a loop with a sequential name?

2 ビュー (過去 30 日間)
catherine
catherine 2014 年 7 月 8 日
編集済み: Jan 2014 年 7 月 8 日
I am using MATLAB R2014a. I am looking to save each output file of a whistle contour as a string with sequential names. At the minute when i run the loop they all open but only the last one saves. This can be 600+ outputs per run and i need them to save instead of open. I would like to save each one twice (one .fig and one .txt). I have a second script to convert from .fig to .txt detailing the details that need to be included.
The two scripts i am working from:
SAVE FILES
tonalsN = tonals.size ();
for tidx = 0 : tonalsN -1
tonal = tonals.get(tidx);
time = tonal.get_time();
freq = tonal.get_freq();
whistle = figure;
plot(time, freq, '-b');
filename = ['whistle_plot.fig', num2str(K)];
save(whistle, 'whistle_plot.fig');
% saveas(whistle, 'whistle_plot.fig'); %just saves last contour in loop but opens all
end
CONVERT .FIG TO .TXT
DATA = dir('C:\Acoustic_data\5_4_Graph_output\*fig');
DATA = rmfield(DATA,'date');
DATA = rmfield(DATA,'bytes');
DATA = rmfield(DATA,'isdir');
dat = {};
for f = 1:size(DATA,1);
load(DATA(f).name,'-fig');
fcontour = fcontour';
dlmwrite([num2str(f,'%03.0f') '.txt'],fcontour(1:(max(size(fcontour))-1)));
dat{f,1} = num2str(f,'%03.0f');
dat{f,2} = DATA(f).name;
dat{f,3} = fcontour(max(size(fcontour)));
end
However this has never worked and needs modifying. Any help and guidance would be greatly appreciated.
  1 件のコメント
Jan
Jan 2014 年 7 月 8 日
I've formatted the code to improve the readability. Please use the "{} Code" button.

サインインしてコメントする。

回答 (2 件)

Michael scheinfeild
Michael scheinfeild 2014 年 7 月 8 日
name =strcat('foo',num2str(ind),'.txt')

Jan
Jan 2014 年 7 月 8 日
編集済み: Jan 2014 年 7 月 8 日
filename = sprintf('whistle_plot%.4d.fig', tidx);
save(whistle, filename);
The leading zeros have the advantage, that the alphabetical order equals the numerical order.

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by