Plotting for a Loop
1 次查看(过去 30 天)
显示 更早的评论
I'm not an experienced Matlab user, but I'm trying to learn. I'm having a problem with plotting the results from my loop. It shows me the graph but there is no data populated in it. Does anybody no have to fix this?
for a=(0:0.01:0.3333333)
C_T=4*a*(1-a)*etaTipLoss
C_P=4*a*(1-a)^2*etaTipLoss*etaDrag
figure(1); plot(a,C_P, "-.r"); hold on
end
0 个评论
采纳的回答
Bob Thompson
2021-2-1
Each time you run the plot command you're only plotting a single point, which doesn't work very well with plot.
I recommend you switch to scatter instead, or index C_p for the loop and run plot outside the loop once.
for a=(0:0.01:0.3333333)
C_T=4*a*(1-a)*etaTipLoss
C_P=4*a*(1-a)^2*etaTipLoss*etaDrag
figure(1); scatter(a,C_P, "-.r"); hold on
end
% or
idx = 0;
for a=(0:0.01:0.3333333)
idx = idx + 1;
C_T=4*a*(1-a)*etaTipLoss
C_P(idx) =4*a*(1-a)^2*etaTipLoss*etaDrag
end
figure(1); plot([0:0.01:0.3333333],C_P, "-.r")
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!