How can I specify a dynamic string variable as filename in the saveas command?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Dennis
el 19 de Jun. de 2018
If Names stores your names as a cell name=Names(i) will return a cell. Try
name=Names{i}
Respuestas (0)
Ver también
Categorías
Más información sobre Printing and Saving en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!