add multiple lines to a single plot without using "hold on/off"
53 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2021-9-20
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:
采纳的回答
Walter Roberson
2021-9-20
%% 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');
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!