Filter löschen
Filter löschen

Plotting for a Loop

3 Ansichten (letzte 30 Tage)
Anders Vigen
Anders Vigen am 1 Feb. 2021
Kommentiert: Anders Vigen am 2 Feb. 2021
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

Akzeptierte Antwort

Bob Thompson
Bob Thompson am 1 Feb. 2021
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")
  1 Kommentar
Anders Vigen
Anders Vigen am 2 Feb. 2021
The second one worked for me! Cheers :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by