Filter löschen
Filter löschen

wrong figure is saved with gcf command

3 Ansichten (letzte 30 Tage)
Mehmet
Mehmet am 2 Sep. 2014
Kommentiert: Adam am 2 Sep. 2014
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.

Antworten (1)

dpb
dpb am 2 Sep. 2014
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 Kommentar
Adam
Adam am 2 Sep. 2014
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by