Hold a plot other than the most recent
8 views (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
Benjamin Thompson
on 2 Feb 2022
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
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!