matlab - 绘图功能线规范
问题描述
我正在尝试在 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
这就是我得到的:
这就是我要的:
我怎样才能用线条制作这个情节?
解决方案
要绘制一条线,该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--')
推荐阅读
- sql - 查询仅在一个日期内获取具有多个会话的实体?
- javascript - setTimeout 现在和给定时间执行
- python-3.x - 使用 BFS 和 IDFS 进行地图着色 - Python 3
- jquery - 如何更改每个数组的字体
- nsis - 在 NSIS SetOverwrite 中模拟不存在的选项“ifNotModified”
- javascript - 如何通过查询字符串将 javascript 变量传递给 html 测试文件
- python - Python - 颜色混合分配
- docker - 在 docker 容器中运行新的风帆
- ruby-on-rails - Nokogiri 未正确解析 XML 字符串
- vercel - 使用 node-config 包,有没有办法在 javascript 中设置 custom-environment-variables.json?