Effacer les filtres
Effacer les filtres

How to activate loop in adress

1 vue (au cours des 30 derniers jours)
Karl
Karl le 30 Sep 2013
Commenté : Karl le 30 Sep 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')

Réponse acceptée

Jan
Jan le 30 Sep 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 commentaire
Karl
Karl le 30 Sep 2013
Thanks for a very helpfull answer!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by