I am trying to plot but I am getting an empty figure

3 次查看(过去 30 天)
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

采纳的回答

Adam Danz
Adam Danz 2020-8-31
编辑:Adam Danz 2020-8-31
There are two problems.
  1. When you're plotting only 1 coordinate at a time, specify a marker type.
  2. You need to apply "hold on" to your axes \
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 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by