필터 지우기
필터 지우기

wrong figure is saved with gcf command

조회 수: 3 (최근 30일)
Mehmet
Mehmet 2014년 9월 2일
댓글: Adam 2014년 9월 2일
I run a simulation from m file. In the simulation, I use some lookup tables. I would like to save some simulation results for different speed and torque values. But, the output is not the plots I wanted. It saves the lookup table (which is plotted before) as .bmp.
This is the gcf part of my code.
saveas(gcf, ['.\caps\currentsDQ', ...
['CurrentDQ @ Speed=' num2str(SpeedCounter) ...
'RMS & Torque =' num2str(Torque_Demand) 'Nm'], '.bmp']);
Ps. this is my first post. if the question is not clear, I am sorry.

답변 (1개)

dpb
dpb 2014년 9월 2일
gcf, as the name implies, returns the handle of the current figure. The current figure is the one that has focus at the time the call is executed (which generally will be the last one referenced in the script/function).
To ensure you save the desired figure, don't rely on gcf but save the handle for the figure that you do want to save when it is created.
hFig=figure; % create a new figure, save the handle
plot(... % make the plot...
Then when you're ready for the saveas call, use the above handle --
saveas(hFig, ...
  댓글 수: 1
Adam
Adam 2014년 9월 2일
I second that. I only ever use gcf when I am doing some quick stuff on command line or a script where the command using gcf is on the same line as the command creating the figure so it can't possibly refer to the wrong figure.
In all other situations I keep track of my own figure handles as dpb suggests.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by