I have 2 massives C<32768x3> Al<20000x3> in which columns are (x,y,z). I need to find out all distances between C and Al. I try:
sqrt(((Al(:,1)-C(:,1))^2)+((Al(:,2)-C(:,2))^2)+((Al(:,3)-C(:,3))^2))
But I got error:
??? Error using ==> minus
Matrix dimensions must agree.

 採用された回答

dpb
dpb 2017 年 4 月 6 日

1 投票

D = pdist2(X,Y);
See
doc pdist2 % note size of result will be length(X)*length(Y)

その他の回答 (3 件)

Image Analyst
Image Analyst 2017 年 4 月 6 日

1 投票

distances = pdist2(C, Al);
pdist2 is in the Statistics and Machine Learning Toolbox. It gives the distance of every point in C to every point in Al.
Jan
Jan 2017 年 4 月 6 日

1 投票

Without the Statistics Toolbox and Matlab >= 2016b:
D = sqrt(((Al(:,1) - C(:,1).') .^ 2) + ...
((Al(:,2) - C(:,2).') .^ 2) + ...
((Al(:,3) - C(:,3).') .^ 2));
Miroslav Zaharov
Miroslav Zaharov 2017 年 4 月 6 日

0 投票

It works! Thanks to all!

Community Treasure Hunt

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

Start Hunting!

Translated by