MATLAB欧式距离的代码优化。

조회 수: 5 (최근 30일)
华纳公司注册账号【987779.tv】
답변: 埃博拉酱 2024년 11월 23일
point = [1 2 3 4 5 6,,,,,n;2 4 3 5 ,,,,,n;.......;128 ,,,,,, ];(point是一个非常大的矩阵:128*n)
dis = [];
tem = [];
for i = 1:length(point)-1
for j = i+1:length(point)
distemp = pdist([alldesc(:,i)';alldesc(:,j)']);
tem = [i j distemp];
dis = [dis;tem];
end
end
简单描述就是:计算矩阵的每一列与其他列的pdist,然后保存数据,可是当point非常大的时候,计算就非常慢,所以想知道有没有更高效的写法

답변 (1개)

埃博拉酱
埃博拉酱 2024년 11월 23일
[dis(:,1),dis(:,2)]=find(tril(true(width(alldesc)),-1));
dis(:,3)=pdist(alldesc.');

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!