How to activate loop in adress

1 回表示 (過去 30 日間)
Karl
Karl 2013 年 9 月 30 日
コメント済み: Karl 2013 年 9 月 30 日
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')

採用された回答

Jan
Jan 2013 年 9 月 30 日
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 件のコメント
Karl
Karl 2013 年 9 月 30 日
Thanks for a very helpfull answer!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by