running a loop and saving separate files

1 回表示 (過去 30 日間)
cgo
cgo 2015 年 12 月 9 日
コメント済み: cgo 2015 年 12 月 10 日
Hi I am running a loop and saving each file separately.
The syntax I am using is
for i = 1:10
RUN PROGRAM
save(sprintf('datafile_%02d',i), 'phi')
end
So this means I am expecting all the phi's to be saved in different filenames. But I only get the most recent (overwritten?) and I do not get 10 separate files.

採用された回答

Image Analyst
Image Analyst 2015 年 12 月 9 日
No, i is changing so the filename is changing. Try to split it up
for k = 1 : 10
% code to RUN PROGRAM and change phi...
% Now save this phi in a new file.
filename = sprintf('datafile_%02d.mat', k);
message = sprintf('About to save phi into new file %s.', filename);
uiwait(helpdlg(message));
save(filename, 'phi');
end
Now see if the filenames are all the same or different.
  2 件のコメント
cgo
cgo 2015 年 12 月 10 日
Hi, I get an error message
undefined function or variable 'k'
how do i proceed?
cgo
cgo 2015 年 12 月 10 日
I found the error. There was a 'clear' function at middle part so everything got erased. It is ok now. Thanks for your help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by