我有一个矩阵,显示了骑士在骑士巡游中的位置。我希望找到首先按顺序查找数字并输出它们的位置的方法,例如在较小的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
,然后连接结果。
然后,我想使用这些信息创建移动的图表,使用线/向量图,但是在如何执行此操作方面遇到了困难。
谢谢, Tessa
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')