How to activate loop in adress

1 visualización (últimos 30 días)
Karl
Karl el 30 de Sept. de 2013
Comentada: Karl el 30 de Sept. de 2013
The loop in the adress in the code below does not work. The stored file gets the filename "fig(Vars2{iVars})" instead of the intented filename "figVariable names Vars". Any ideas on how to fix this?
Vars = {FordH};
Vars2 = {'Variable names Vars'};
for iVars = 1:length(Vars);
aVars = Vars{iVars};
fig = figure,title(Vars2{iVars});
hold on
plot(aVars(:,:));
end
hold off
print(fig,'-dpng','Q:\\XX\\Matlab\\YY\\Figures\\fig(Vars2{iVars}).png')

Respuesta aceptada

Jan
Jan el 30 de Sept. de 2013
Yes, of course the file get the name you have specified. Anything between the single quotes is a string, an Matlab cannot guess, that you want the characters to be interpreted as name of a variable. This would be too magic.
The code contains several problems:
  1. The iVars loop is closed by end before the print command. In each iteration a new figure is created and only the last one is printed. But inside the print command, you want to use the loop counter iVars. The value of the loop counter is not well defined outside the loop, so if this is really the wanted behavior, prefer Vars2{end}.
  2. It seems like "Q:\\XX\\Matlab\YY" could be the Matlab root folder. If so, don't do this. Never write files into Matlab's root directory.
  3. If you want Vars{iVars} to be interpreted as variable:
print(fig,'-dpng', ['Q:\\XX\\Matlab\\YY\\Figures\\fig(', Vars2{iVars}), '.png'])
But "fig(Variable names Vars).png" is still a strange name.
  1 comentario
Karl
Karl el 30 de Sept. de 2013
Thanks for a very helpfull answer!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by