MATLAB: Plotting a graph from for loops

forfor loopgraphplottwo loops

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.

Best Answer

  • 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?