plotting in same figure window

It's needed while using same plot command, it plots in the same figure window and not in another figure window
for example:
h1 = figure;
plot(randn(100,1));
figure(h1)
now while using same above plot command, it's needed that plots in the same figure window and not in another figure window

 Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 18 Sep 2011

1 vote

>> help figure
FIGURE Create figure window.
FIGURE, by itself, creates a new figure window, and returns
its handle.
FIGURE(H) makes H the current figure, forces it to become visible,
and raises it above all other figures on the screen. If Figure H
does not exist, and H is an integer, a new figure is created with
handle H.
So, if you want to always plot on the same figure, you can use h=figure(1), which may not be good in some cases because it over-write the existing figure 1.
Or, you can use close() to close the existing figure first.
In any case, remember figure has a handle. It is like the figure's ID. You can always specify to which figure you want to plot.
h1=figure(1);
set(h1,'name','myname');
plot(1:10);

Plus de réponses (1)

Wayne King
Wayne King le 18 Sep 2011

0 votes

Do you want the plot to replace what is already there and keep the same axes?
h1 = figure;
plot(randn(100,1));
figure(h1)
ax = gca;
plot(ax,randn(100,1),'r');
Or do you want the plot to be in addition to what is there with the same axes?
h1 = figure;
plot(randn(100,1));
figure(h1)
ax = gca; hold on;
plot(ax,randn(100,1),'r');
Wayne

4 commentaires

mohammad
mohammad le 18 Sep 2011
when i copy and paste all of under commands in command window:
h1 = figure;
plot(randn(100,1));
figure(h1)
it plots a figure in name of figure1
then while again i copy and past all above command in command window it plots a figure in name of figure2. but i want it plots on figure1 and not in another window(not in figure2). and not coming up a new figure window
Fangjun Jiang
Fangjun Jiang le 18 Sep 2011
In that case, use h1=figure(1) instead.
Fangjun Jiang
Fangjun Jiang le 18 Sep 2011
See update in my answer.
mohammad
mohammad le 18 Sep 2011
so thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by