Plotting for a Loop

4 visualizzazioni (ultimi 30 giorni)
Anders Vigen
Anders Vigen il 1 Feb 2021
Commentato: Anders Vigen il 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

Risposta accettata

Bob Thompson
Bob Thompson il 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 Commento
Anders Vigen
Anders Vigen il 2 Feb 2021
The second one worked for me! Cheers :)

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by