简体   繁体   English

如何通过绘图连接点

[英]How connect points by using plot

The problem with my code is that it plots discrete points without connecting them together. 我的代码的问题在于它绘制离散点而不将它们连接在一起。

Related code: 相关代码:

for i:1:100
    wx(i,1)= Related formula
    figure(1)
    plot(i,wx(i,1),'r.-')
    line(i,wx(i,1))
    axis([0,i,-10,10])
    hold on
end

Result has been shown in the image below; 结果显示在下图中;

How can I connect them together? 如何将它们连接在一起?

The plot function can only join points with a line if you enter all the endpoints of the line in an array. 如果在数组中输入线的所有端点,则plot功能只能将点与线连接。 If you send them one by one, it will only plot discrete points without connecting them. 如果将它们一一发送,它将仅绘制离散点而不连接它们。 It is recommended to compute all the points in the array first, before sending them all to the plot function at once. 建议先计算数组中的所有点,然后再将所有点立即发送到plot函数。

The easiest solution here would be: 这里最简单的解决方案是:

for i = 1:100
  x(i) = i
  wx(i,1) = related_formula()
end

figure(1)
plot(x, wx(:,1), 'r.-')
axis([0,i,-10,10])
i =1:100;
wx=Related formula(i);
figure(1)
plot(i,wx,'r.-')
axis([0,i,-10,10])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM