Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Maria Galle
Maria Galle am 31 Aug. 2020
Bearbeitet: Adam Danz am 31 Aug. 2020
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

Akzeptierte Antwort

Adam Danz
Adam Danz am 31 Aug. 2020
Bearbeitet: Adam Danz am 31 Aug. 2020
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).

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by