Saving variables and figures uniquely when processing a sequence of files

1 view (last 30 days)
Andrew on 15 Feb 2013
I am trying to save a variable (A) with the num2str(k)so that I can run multiple files at once, but keep getting an error.
example: hgsave('SummaryPlot' num2str(ii)); and hgsave('SummaryPlot' num2str(ii),'.txt');
If there a better way to do this?

Accepted Answer

Kye Taylor
Kye Taylor on 15 Feb 2013
Edited: Kye Taylor on 15 Feb 2013
notice the square brackets in order to concatenate 'SummaryPlot' and the output from num2str(ii). Same with

More Answers (1)

Image Analyst
Image Analyst on 15 Feb 2013
Edited: Image Analyst on 15 Feb 2013
If you're familiar with C, you'll probably prefer the sprintf() way:
baseFileName = sprintf('Summary Plot %d.txt' ii);
fullFileName = fullfile(yourFolder, baseFileName);
yourFolder could be "pwd" - the current folder - if you wish. Also, please consider export_fig instead of hgsave:

Community Treasure Hunt

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

Start Hunting!