How can I specify a dynamic string variable as filename in the saveas command?
6 ビュー (過去 30 日間)
古いコメントを表示
There have been lots of questions on very similar issues already, but I can't quite get hold onto my specific problem. Say I have a cell vector with some names of chemical compounds and I want to produce plots of some properties of each one of those compounds, which I do using a simple loop. Now I would like to access the name of the compound when I am calling the saveas command, so the figure I am saving has the name of the compound and I therefore can quickly find it. I am getting the error message of using an invalid filename. My code looks something like this:
for I=1:10
x=propertyone(I,:);
y=propertytwo(I,:);
name=Names(I);
plot(x,y);
saveas(gcf,name,'jpeg')
end
I have no problem whatsoever naming the figures dynamically doing something like this:
for I=1:10
x=propertyone(I,:);
y=propertytwo(I,:);
name=Names(I);
plot(x,y);
saveas(gcf,['file',num2str(I)],'jpeg')
end
But I would very much like to have the proper names of the compounds instead of just a number. The problem seems to arise from defining the name variable within the loop, but I cannot figure out a solution.
I would appreciate any suggestions regarding this (rather specific) problem.
Best, Alex
3 件のコメント
Dennis
2018 年 6 月 19 日
If Names stores your names as a cell name=Names(i) will return a cell. Try
name=Names{i}
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Printing and Saving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!