绘制功能线规格

时间:2018-10-01 23:07:12

标签: matlab plot

我正在尝试在MATLAB中使用直线绘制图形;但是,我只能使用圆点打印它。

我尝试用“ r-”和其他不同的解决方案更改“ ro-”,但没有任何效果。使用“ r-”时,它不会打印任何内容。

这是我的代码:

for T = temp
  figure(i)
  for xb = linspace (0,1,10)
    xt = 1-xb;
    Pb = 10^(6.89272 - (1203.531/(T+219.888)));
    Pt = 10^(6.95805 - (1346.773/(T+219.693)));
    Ptot = Pb*xb + Pt*xt;
    yb = (Pb*xb)/Ptot;
    plot(xb, Ptot, 'bo-.')
    hold on
    plot(yb, Ptot, 'ro-')
  end
  i = i + 1;
  saveas(gcf, filename, 'png')
end

这就是我得到的:

enter image description here

这就是我想要的:

enter image description here

如何用线绘制该图?

1 个答案:

答案 0 :(得分:0)

要绘制线,plot命令必须在一个函数调用中获得沿线的所有点。重复调用plot将在图形上添加新线,在这种情况下,每条线都由一个点组成。简而言之,MATLAB不知道您要连接这些点。

那么,如何将所有数据点放在一个阵列中?只需将它们存储在循环中即可:

T = 70;
xb = linspace(0,1,10);
Plot = zeros(size(xb)); % preallocate output array
yb = zeros(size(xb));   % preallocate output array
for ii=1:numel(xb)
  xt = 1-xb(ii);
  Pb = 10^(6.89272 - (1203.531/(T+219.888)));
  Pt = 10^(6.95805 - (1346.773/(T+219.693)));
  Ptot(ii) = Pb*xb(ii) + Pt*xt;
  yb(ii) = (Pb*xb(ii))/Ptot(ii);
end
figure
plot(xb, Ptot, 'b-')
hold on
plot(yb, Ptot, 'r--')

但是实际上,根本不需要循环就更容易做到这一点:

T = 70;
xb = linspace(0,1,10);
xt = 1-xb;
Pb = 10^(6.89272 - (1203.531/(T+219.888)));
Pt = 10^(6.95805 - (1346.773/(T+219.693)));
Ptot = Pb*xb + Pt*xt;
yb = (Pb*xb)./Ptot;    % note ./ is the element-wise division
figure
plot(xb, Ptot, 'b-')
hold on
plot(yb, Ptot, 'r--')