# How to find euclidean distances between cell entries of two RGB matrices?

1 view (last 30 days)

Show older comments

##### 3 Comments

### Answers (1)

Jan
on 16 Nov 2020

A = rand(47, 47, 3);

B = rand(1, 456 3);

AB = reshape(A, 47*47, 1, 3) - B;

Dist = vecnom(AB, 2, 3);

And now you want to find the minimal values in each column. Afterwards you can use ind2sub to convert the linear indices back to the indices of A.

Another option is a simple loop:

Result = zeros(size(A));

for row = 1:47

for col = 1:47

dist = vecnorm(A(col, row, :) - B, 2, 3);

[~, index] = min(dist);

Result(col, row) = index;

end

end

##### 2 Comments

Jan
on 18 Nov 2020

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!