i want to find distances between coordinate points as i explained below?? any help??

2 visualizzazioni (ultimi 30 giorni)
i have coordinates as
A = (0,0); B = (1,0); C = (2,0)
D = (0,1); E = (1,1); F = (2,1)
G = (0,2); H = (1,2); I = (2,2)
i want to distance between A to D plus D to B and so on......
matrix 1 (2*3)
[(AtoD+DtoB) (AtoE+EtoB) (AtoF+FtoB)
(AtoG+GtoB) (AtoH+HtoB) (AtoI+ItoB)
matrix 2 (2*3)
[(AtoD+DtoC) (AtoE+EtoC) (AtoF+FtoC)
(AtoG+GtoC) (AtoH+HtoC) (AtoI+ItoC)
matrix 3 (2*3)
[(BtoD+DtoA) (BtoE+EtoA) (BtoF+FtoA)
(BtoG+GtoA) (BtoH+HtoA) (BtoI+ItoA) ]
matrix 4 (2*3)
[(BtoD+DtoC) (BtoE+EtoC) (BtoF+FtoC)
(BtoG+GtoC) (BtoH+HtoC) (BtoI+ItoC) ]
matrix 5 (2*3)
[(CtoD+DtoA) (CtoE+EtoA) (CtoF+FtoA)
(CtoG+GtoA) (CtoH+HtoA) (CtoI+ItoA) ]
matrix 6 (2*3)
[(CtoD+DtoB) (CtoE+EtoB) (CtoF+FtoB)
(CtoG+GtoB) (CtoH+HtoB) (CtoI+ItoB) ]
finally i want six matrices as i explained above
thank you
  6 Commenti
darova
darova il 8 Ago 2019
matrix 1 == matrix 3
matrix 2 == matrix 5
matrix 4 == matrix 6
What do you think? Does it make your task easier?

Accedi per commentare.

Risposta accettata

darova
darova il 8 Ago 2019
With use of pdist2()
A = [0 0]; B = [1 0]; C = [2 0];
[x,y] = meshgrid(0:2,1:2); % D G E H F I
D_I = [x(:) y(:)];
AtoXY = reshape(pdist2(A, D_I),size(x)); % matrix distance from A to (D G E H F I)
BtoXY = reshape(pdist2(B, D_I),size(x)); % distance from B
CtoXY = reshape(pdist2(C, D_I),size(x)); % distance from C
matrix1 = AtoXY + BtoXY;
matrix2 = AtoXY + CtoXY;
matrix4 = BtoXY + CtoXY;
  13 Commenti
M.Prasanna kumar
M.Prasanna kumar il 9 Ago 2019
Modificato: M.Prasanna kumar il 9 Ago 2019
sir,
thank your very much for your kind reply. you were replying very patiently
code is working perfectly

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by