Plotting a graph from for loops

1 view (last 30 days)
J122
J122 on 28 Mar 2015
Edited: Star Strider on 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.

Accepted Answer

Star Strider
Star Strider on 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 Comments
J122
J122 on 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 on 28 Mar 2015
Edited: Star Strider on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!