필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Maria Galle
Maria Galle 2020년 8월 31일
편집: Adam Danz 2020년 8월 31일
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