필터 지우기
필터 지우기

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 CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by