pdist2 with wrapping
Mostrar comentarios más antiguos
I have a square area of gridpoints and I'm trying to create a graph where each point is joined to its neighbouring points based on a Chebychev distance. From an earlier question here, I have the following methodology:
M = 50; N = 50;
[I,J] = ndgrid(1:M,1:N);
IJ = [I(:),J(:)];
[W,K] = pdist2(IJ,IJ,'chebychev','Smallest',9);
From here, columns of W containing only 1 can be selected and can be matched with columns of K to get the adjacency matrix. In this case however, I want to create a graph where the edges of the square are wrapped, that is, the leftmost (or topmost) points are also connected to the rightmost (or bottommost) points. How can I add this condition in pdist2?
Respuestas (2)
Rik
el 21 de En. de 2021
0 votos
You could maybe modify the internal code of pdist2, but you should not do that. The easiest way here is to just create copies of your array with repmat. Don't forget to remove the padding from the result as well.
4 comentarios
Tejas
el 21 de En. de 2021
Rik
el 21 de En. de 2021
I meant something like this:
IJ=repmat(IJ,3,3);
[W,K] = pdist2(IJ,IJ,'chebychev','Smallest',9);
You will have to do something with W and K to account for all the rows and columns you added.
Rik
el 22 de En. de 2021
I never claimed this would be efficient. It would work, that is all.
Tejas
el 22 de En. de 2021
Categorías
Más información sobre Graph and Network Algorithms en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!