# Find the position of elements of an array in another array and measure the euclidean distance between two array elements.

3 visualizzazioni (ultimi 30 giorni)
Md. Asadujjaman il 19 Feb 2022
Modificato: Md. Asadujjaman il 19 Feb 2022
Suppose,
X = [11 12 13 21 22 23]
A = [11 22 21 13 12 23]
B = [11 13 21 23 22 12]
At first, I want to find the position of each elements of X in A and B. The answer would be as follows.
Position of X elements in A, P = [1 5 4 3 2 6]
Position of X elements in B, Q = [1 6 2 3 5 4]
Now I want to measure the euclidean distance between the elements of P and Q.
How can I do these?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Ive J il 19 Feb 2022
X = [11 12 13 21 22 23];
A = [11 22 21 13 12 23];
B = [11 13 21 23 22 12];
[~, Q] = ismember(X, B)
Q = 1×6
1 6 2 3 5 4
[~, P] = ismember(X, A)
P = 1×6
1 5 4 3 2 6
norm(P - Q)
ans = 4.2426
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

KSSV il 19 Feb 2022
d = sqrt(sum((A(X)-B(X)).^2));
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by