How can I specify a dynamic string variable as filename in the saveas command?

4 次查看(过去 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 个评论

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by