Plotting a graph from for loops

1 vue (au cours des 30 derniers jours)
J122
J122 le 28 Mar 2015
Modifié(e) : Star Strider le 28 Mar 2015
My script:
for temp=298:10:800
u = (temp+2139.5)/4875;
end
for u=0.5:0.001:0.6025
Tp = 1/3*(1.57-0)*u*6000000*(0.16^3-0.08^3);
end
I want to plot Tp against temp but cannot figure out how to.

Réponse acceptée

Star Strider
Star Strider le 28 Mar 2015
You don’t need the for loops, since MATLAB can do the matrix calculations without them:
temp=298:10:800;
u = (temp+2139.5)/4875;
Tp = 1/3*(1.57-0)*u*6000000*(0.16^3-0.08^3);
figure(1)
plot(temp, Tp)
grid
xlabel('temp')
ylabel('Tp')
Does this do what you want?
  4 commentaires
J122
J122 le 28 Mar 2015
I have done so, this is part of the error message: 'Attempt to execute SCRIPT plot as a function'
Star Strider
Star Strider le 28 Mar 2015
Modifié(e) : Star Strider le 28 Mar 2015
I have absolutely no idea what you are doing. Start with a completely new Editor tab, paste my code to it, and with that tab open, click on the green Run button in the Editor toolstrip at the top of the Editor window. That should work.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by