Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Setting figure before plot

Subject: Setting figure before plot

From: Maxx Chatsko

Date: 21 Jul, 2010 13:38:04

Message: 1 of 5

Hello all,
   I have a gui that creates several plots in different windows. Obviously, the program will create the plot in the current figure. This is problematic if the user re-selects the main control figure right before the program creates the plot because it will appear in the background of the main control figure, not in the intended new figure (which is empty). I tried using set(gcf,'myfigure') and other commands...what command would I write before plot() to set the figure?
          Thanks
          Maxx

Subject: Setting figure before plot

From: Maxx Chatsko

Date: 21 Jul, 2010 13:50:08

Message: 2 of 5

    I meant that I used figure() not set(), but I can't get the handle of the figure to put in the command figure()...any idears?

Subject: Setting figure before plot

From: us

Date: 21 Jul, 2010 13:53:03

Message: 3 of 5

"Maxx Chatsko" <chatskom@chemimage.com> wrote in message <i26t7s$ikf$1@fred.mathworks.com>...
> Hello all,
> I have a gui that creates several plots in different windows. Obviously, the program will create the plot in the current figure. This is problematic if the user re-selects the main control figure right before the program creates the plot because it will appear in the background of the main control figure, not in the intended new figure (which is empty). I tried using set(gcf,'myfigure') and other commands...what command would I write before plot() to set the figure?
> Thanks
> Maxx

one of the solutions

     fh(1)=figure('name','fig1');
     plot(1:10);
     fh(2)=figure('name','fig2');
     disp('press any key to cont...');
     pause;
     figure(fh(1));

us

Subject: Setting figure before plot

From: Yuri Geshelin

Date: 21 Jul, 2010 13:59:05

Message: 4 of 5

"Maxx Chatsko" <chatskom@chemimage.com> wrote in message <i26t7s$ikf$1@fred.mathworks.com>...
> Hello all,
> I have a gui that creates several plots in different windows. Obviously, the program will create the plot in the current figure. This is problematic if the user re-selects the main control figure right before the program creates the plot because it will appear in the background of the main control figure, not in the intended new figure (which is empty). I tried using set(gcf,'myfigure') and other commands...what command would I write before plot() to set the figure?
> Thanks
> Maxx

figure(N),

where N is the handle to the desired figure. If that figure exists, it will become current. Otherwise, it will be created.

Yuri

Subject: Setting figure before plot

From: Walter Roberson

Date: 21 Jul, 2010 16:35:57

Message: 5 of 5

Maxx Chatsko wrote:

> I have a gui that creates several plots in different windows.
> Obviously, the program will create the plot in the current figure. This
> is problematic if the user re-selects the main control figure right
> before the program creates the plot because it will appear in the
> background of the main control figure, not in the intended new figure
> (which is empty). I tried using set(gcf,'myfigure') and other
> commands...what command would I write before plot() to set the figure?

Don't do it that way. Instead, use explicit specification of the figure
number or axes or uipanel (or as appropriate) for every graphics
operation. The more common graphics operation often allow the parent to
be specified as the first parameter; the great majority of the other
graphic operations allow the parent to be specified by giving a 'Parent'
property in the calling list.

f = figure(123);
ax = axes('Parent', f);
plot(ax, rand(3,5));
line([0 0], [1 1], 'Parent', ax);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us