Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify to which figure a plot should go?

Tags:

plot

matlab

I have multiple figures open, and I want to update them independently during runtime. The following toy example should clarify my intention:

clf;

figure('name', 'a and b'); % a and b should be plotted to this window
hold on;
ylim([-100, 100]);

figure('name', 'c'); % only c should be plotted to this window

a = 0;
b = [];
for i = 1:100
    a = a + 1;
    b = [b, -i];
    c = b;
    xlim([0, i]);
    plot(i, a, 'o');
    plot(i, b(i), '.r');
    drawnow;
end

The problem here is that when I open the second figure, I cannot tell the plot functions to plot to the first one instead of the second (and only c should be plotted to the second).

like image 543
István Zachar Avatar asked Mar 02 '12 11:03

István Zachar


People also ask

How do you plot a figure in MATLAB?

plot( X , Y ) creates a 2-D line plot of the data in Y versus the corresponding values in X . To plot a set of coordinates connected by line segments, specify X and Y as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X or Y as a matrix.

How do you name a figure window in MATLAB?

Go to "Edit" in the figure window. Go to "Figure Properties" At the bottom, you can type the name you want in "Figure Name" field. You can uncheck "Show Figure Number".

Which command is used for plotting?

Plots a drawing to a plotter, printer, or file in the command line.


1 Answers

You can use something like

figure(1)
plot(x,y) % this will go on figure 1

figure(2)
plot(z,w) % this will go on another figure

The command will also set the figure visible and on top of everything.

You can switch back and forth between the figures as necessary by issuing the same figure command. Alternatively, you can use the handle to the figure as well:

h=figure(...)

and then issue figure(h) instead of using numeric indices. With this syntax, you can also prevent the figure from popping up on top by using

set(0,'CurrentFigure',h)
like image 144
mindcorrosive Avatar answered Oct 01 '22 02:10

mindcorrosive