Plotting Points from Matrix to Matrix

I have a matrix that shows me the positions of a knight on a knight's tour. I'm looking to find a way to find the numbers in order first and output their positions, for example. on a smaller board X

X=[1 3; 4 2]

      

OUTPUT

A=[1 2 3 4]

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

      

Something like this, where b is the position of the A values ​​in the matrix

the only way I can think of it is using a series function find (n)

where n=1..64

and then concatenate the results

Then I want to use this information to create a motion plot with a line / vector plot, but I am also having a hard time figuring out how.

Thanks, Tessa

+3


source to share


1 answer


You can use find

to determine visited code coordinates and then sort them according to move order.



%# 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')

      

+3


source







All Articles