Hold a plot other than the most recent

If I make a plot and then another plot and later want to add another line to the first plot, is there a way to do this using the hold function or any otehr functions? Basically is there a way to reference the plot you want to add to or will it only had to the most recent plot in the script?

Antworten (2)

Benjamin Thompson
Benjamin Thompson am 2 Feb. 2022

1 Stimme

You can use the figure function to "select" any previously created figure window, as long as you have the figure handle or the figure number. In this example, the first plot is held, and the third call to plot will add a red-colored sinusoid line to the first plot. The second figure window only gets one sinusoid plot in the default color of blue.
>> fig1 = figure;
>> t = 0:10;
>> x1 = 1/2*9.806*t.^2;
>> plot(t, x1)
>> fig2 = figure;
>> x2 = sin(t);
>> plot(t, x2)
>> figure(fig1), hold on
>> plot(t, 2*x2, 'r')
>> hold off

Kategorien

Mehr zu Line Plots finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 2 Feb. 2022

Beantwortet:

am 2 Feb. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by