How can I specify a dynamic string variable as filename in the saveas command?
조회 수: 1 (최근 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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!