- When you're plotting only 1 coordinate at a time, specify a marker type.
- You need to apply "hold on" to your axes \
I am trying to plot but I am getting an empty figure
2 views (last 30 days)
Show older comments
I am trying to plot but I am getting an empty figure. I am not sure what is wrong with my code.
for Tf=32:1:212
p=133.3*exp(20.386-(51.32/((9/5)*Tf+32)))
zf(1) = figure(1);
za(1) = axes;
plot(Tf,p,'r')
xlabel('Temperature (F)')
ylabel('Pressure (Pa)')
xlim([0 215]);
ylim([0 10e10]);
end
0 Comments
Accepted Answer
Adam Danz
on 31 Aug 2020
Edited: Adam Danz
on 31 Aug 2020
There are two problems.
Also, there are other inefficiencies in your loop. See the reconstructed loop and comments below.
% Move this stuff out of the loop!
zf(1) = figure(1);
za(1) = axes;
hold(za(1), 'on') % <--- don't forget this!
for Tf=32:1:212
p=133.3*exp(20.386-(51.32/((9/5)*Tf+32))); % <-- suppress output with ";"
plot(Tf,p,'ro') %<--- specify a marker!
end
% Move this stuff out of the loop!
xlabel('Temperature (F)')
ylabel('Pressure (Pa)')
xlim([0 215]);
ylim([0 10e10]);
The loop can be replaced with vectorized format. This version below is much more efficient and produces the same plot (except for line style).
Tf = 32:1:212;
p = 133.3*exp(20.386-(51.32./((9/5).*Tf+32)));
plot(Tf,p,'b','lineWidth',2)
The plot below shows the loop method (red markers) and the vectorized method (blue line).
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots 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!