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?
답변 (2개)
Benjamin Thompson
2022년 2월 2일
1 개 추천
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
Fangjun Jiang
2022년 2월 2일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!