Effacer les filtres
Effacer les filtres

wrong figure is saved with gcf command

3 vues (au cours des 30 derniers jours)
Mehmet
Mehmet le 2 Sep 2014
Commenté : Adam le 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.

Réponses (1)

dpb
dpb le 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 commentaire
Adam
Adam le 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks 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