Substract Matrix coloum-wise from Matrix without using a loop
조회 수: 13 (최근 30일)
이전 댓글 표시
Hello,
is there a way to substract all coloumns of one matrix one by one from another matrix without using a loop?
I am trying to calculate the minimum distance of all the 3D points in matrix B to all the points in matrix A, where A = [109x3]; B = [109x3].
WITH a loop I would do it that way:
for n=109:-1:1
distance(n) = min(sqrt(sum((A - B(n,:)).^2,2)));
end
I was thinking of the repmat function but cant quite figure it out.
Thank your very much!
댓글 수: 0
채택된 답변
추가 답변 (1개)
JESUS DAVID ARIZA ROYETH
2019년 11월 7일
if you have Statistics and Machine Learning Toolbox :
distance=min(pdist2(A,B));
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!