Effacer les filtres
Effacer les filtres

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

111 vues (au cours des 30 derniers jours)
cdlapoin
cdlapoin le 20 Sep 2021
Commenté : cdlapoin le 20 Sep 2021
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 commentaires
Stephen23
Stephen23 le 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 le 20 Sep 2021
Thanks, that is what I was looking for

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 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');

Plus de réponses (0)

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by