add multiple lines to a single plot without using "hold on/off"

54 Ansichten (letzte 30 Tage)
I have a function that creates two plots, I want to run that function in a for loop but have the plots updated with the new lines rather than create new plots. If I use hold on, then the two different types of plot will be on the same set of axis so I don't want that.
%% Create Plots
% Would like pressure dist overlaid on airfoil shape
tiledlayout(2,1);
ax1 = nexttile;
plot(x,y);
hold on;
for i=1:numPanels
p = [loc(i,1) loc(i,2); loc(i,1)-0.1*Cp(i)*normVect(i,1) loc(i,2)-0.1*Cp(i)*normVect(i,2)];
plot(p(:,1),p(:,2));
end
hold off
% plot CP dist below with same x-axis
ax2 = nexttile;
plot(loc(:,1),Cp);
linkaxes([ax1 ax2],'x');
set(ax2, 'YDIR','reverse');
so with this example code I would like the first plot to conitunally update ax1 on each itteration and the second to update ax2 for each itteration.
Thank you
  2 Kommentare
Stephen23
Stephen23 am 20 Sep. 2021
The solution, just like all robust graphics, is to explicitly obtain and refer to all graphics objects via their handles.
As soon as you move beyond simple plotting one line in one figure, then you need to start working with handles:
cdlapoin
cdlapoin am 20 Sep. 2021
Thanks, that is what I was looking for

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 20 Sep. 2021
%% Create Plots
% Would like pressure dist overlaid on airfoil shape
tiledlayout(2,1);
ax1 = nexttile;
plot(ax1,x,y);
hold(ax1,'on');
for i=1:numPanels
p = [loc(i,1) loc(i,2); loc(i,1)-0.1*Cp(i)*normVect(i,1) loc(i,2)-0.1*Cp(i)*normVect(i,2)];
plot(ax1, p(:,1),p(:,2));
end
hold(ax1, 'off')
% plot CP dist below with same x-axis
ax2 = nexttile;
plot(ax2, loc(:,1), Cp);
linkaxes([ax1 ax2],'x');
set(ax2, 'YDIR','reverse');

Weitere Antworten (0)

Kategorien

Mehr zu Graphics finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by