Use pdist() and vertcat() using for loop

조회 수: 1 (최근 30일)
Kong
Kong 2020년 3월 4일
댓글: Kong 2020년 3월 4일
Hey. Gays!
I wanna calculate pairwise euclidean distance and stack this Concatenate arrays vertically.
X = rand(7,7);
n = size(X,2);
for i=1:n
C = vertcat(pdist(X(:,i)));
end
I want to get the result (7 x 21) which was stacked.
However, I just got (1 x 21) matrix.
Does anyone have idea to fix this for loop code?

채택된 답변

Matt J
Matt J 2020년 3월 4일
X = rand(7,7);
n = size(X,2);
C=cell(n,1);
for i=1:n
C{i}=pdist(X(:,i));
end
C=cell2mat(C);
  댓글 수: 1
Kong
Kong 2020년 3월 4일
It's perfect solution! Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by