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!