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

plotting

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

Best Answer

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).
Related Question