在matlab上绘制矩阵点

时间:2013-02-17 13:31:46

标签: matlab sorting vector matrix plot

我有一个矩阵,向我展示骑士之旅中骑士的位置。我正在寻找一种方法,首先按顺序查找数字并输出它们的位置,例如在较小的板上X

X=[1 3; 4 2]

输出

A=[1 2 3 4]

b= [1 1; 2 4; 1 2; 1 3] 

像这样的东西,其中b是矩阵

中A值的位置

我能想到这样做的唯一方法是使用find (n)的系列函数n=1..64,然后连接结果

然后我想使用这些信息来创建一个带有线/矢量图的动作图,但是我也很难弄清楚如何做到这一点。

谢谢, 泰莎

1 个答案:

答案 0 :(得分:3)

您可以使用find来识别所访问的棋盘坐标,然后根据移动的顺序对它们进行排序。

%# find the visited coordinates
[rows,cols,moveNumber]=find(A);

%# find out how to reorder the positions so that
%# the moves are in the right order
[~,sortIdx] = sort(moveNumber);

%# plot the moves
figure
plot(rows(sortIdx),cols(sortIdx),'-o')
相关问题