Use pdist() and vertcat() using for loop

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 日

0 投票

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 件)

質問済み:

2020 年 3 月 4 日

コメント済み:

2020 年 3 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by