matlab 画 矩阵点,在MATLAB中绘制矩阵中点之间的线

3 个答案:

答案 0 :(得分:1)

这适用于我的数据结构:

data = [

0, 0, 1, 0;...

1, 0, 1, 1;...

1, 1, 0, 1;...

0, 1, 0, 0 ...

];

figure(1);

hold off;

%slow way

for i = 1:size(data, 1)

plot([data(i, 1) data(i, 3)], [data(i, 2) data(i, 4)], 'r-');

hold on;

end

%fast way ("vectorized")

plot([data(:, 1)' data(:, 3)'], [data(:, 2)' data(:, 4)'], 'b-');

axis equal

这个特殊的例子描绘了一个正方形。

关键是MATLAB在参数中绘制列式行。也就是说,如果plot的参数具有n列,则该行将具有n -1个段。

在“连接点”方案中,必须连接向量中的所有点,这是无关紧要的,因为如果需要,MATLAB将转置以获得列向量。它在我的应用程序中变得很重要,因为我不想要连接列表中的每个点 - 只有一对点。

答案 1 :(得分:1)

我来到这里寻找相同的答案。我基本上想要每个x,y点的水平线,从该点的x-y值开始,并以下一个xy对的x值结束,没有将该段连接到下一个xy对的线。我可以通过在旧的y和新的x之间添加新点来制作片段,但我不知道如何分割线段。但你的措辞(矩阵)给了我一个想法。如果你将xy对加载到一对x,y向量并且 - 等待它 - 在x和y向量中用nan分隔你的对,该怎么办?我用很长的正弦波尝试了它,它似乎工作。大量不相交的线段,即刻绘制和缩放。 :)看看它是否解决了你的问题。

% LinePairsTest.m

% Test fast plot and zoom of a bunch of lines between disjoint pairs of points

% Solution: put pairs of x1,y1:x2,y2 into one x and one y vector, but with

% pairs separated by x and or y = nan. Nan is wonderful, because it leaves

% your vector intact, but it doesn't plot.

close all; clear all;

n = 10000; % lotsa points

n = floor(n/3); % make an even set of pairs

n = n * 3 - 1; % ends with a pair

x = 1:n; % we'll make a sine wave, interrupted to pairs of points.

% For other use, bring your pairs in to a pair of empty x and y vectors,

% padding between pairs with nan in x and y.

y = sin(x/3);

ix = find(0 == mod(x,3)); % index 3, 6, 9, etc. will get...

x(ix) = nan; % nan.

y(ix) = nan; % nan.

figure;

plot(x,y,'b'); % quick to plot, quick to zoom.

grid on;

答案 2 :(得分:-1)

尝试line例如

X=[1:10 ; 2*(1:10)];

Y=fliplr(X);

line(X,Y)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值