【问题标题】:Line plot - Matlab线图 - Matlab
【发布时间】:2021-12-29 16:25:20
【问题描述】:

当我运行这段代码时:

pts= [-1 0; 0 1; 1 0; 0 -1];
xCenter = 0;
yCenter = 0;
plot(xCenter,yCenter,pts(:,1), pts(:,2),'g');

我得到了这个情节:

我需要改变什么,所以我将绘制 + 号,所有的行都将从中心开始。

【问题讨论】:

  • 是的。这就是我为之奋斗的原因。我也试过:for i = 1 : length(pts) plot(xCenter,yCenter,pts(i,1), pts(i,2),'g'); end

标签: matlab


【解决方案1】:

只需在每对点之间添加原点

pts= [-1 0; 0 0; 0 1; 0 0; 1 0; 0 0; 0 -1];

否则你会在“+”的端点之间跳过,这就是为什么你会得到一个正方形的 3 个边。

你可以用类似的东西自动做到这一点

pts= [-1 0; 0 1; 1 0; 0 -1];
xCenter = 0;
yCenter = 0;

% Initialise the array to all be the center point
newPts = repmat( [xCenter, yCenter], size(pts,1)*2-1, 1 );
% Every other row comes from the original "pts"
newPts(1:2:2*size(pts,1),:) = pts;

【讨论】:

  • 谢谢。有没有一种更有效的方法来自动创建一个新的 pts (newPts),在原始 pts 的每个奇数元素之后都有 xCenter,yCenter (0,0)?
  • @alirazi 查看我的编辑
猜你喜欢
  • 1970-01-01
  • 2014-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-27
相关资源
最近更新 更多