From: Eirik Paulsen on 7 Jul 2010 05:04 Hi, I am simulating an animal, which moves like the king on a chess board. I want to make a matrix looking exactly like the illustration here: http://en.wikipedia.org/wiki/Chebyshev_distance The purpose is to calculate the distance from the animal's position to every square on the board. I have made this pseudocode:: %------------------------------ x = boardSizeX; %column size y = boardSizeY; %row size position = [posX, posY]; %position of animal indices = transpose([1:x 1:x 1:x ... ; ones(1,x) 2*ones(1,x) 3*ones(1,x); ... ]) % ... means y times distances = pdist2(indices ,position ,'chebychev'); distanceMatrix = reshape(distances,x,y); %-------------------------------- This is not very elegant. Does anyone have any idea of how to make it a little more elegant? Thanks!
|
Pages: 1 Prev: NNtool box information Next: Boundary in Black and White image |