Optimal distance calculation for a data cube

I'm wondering if there's a better way to calculate my distance matrix?
function D = frame2frameDist(imageStack)
[h, w, c, l] = size(imageStack);
D = zeros(l);
for channel = 1:c
for i = 1:l
for j = i:l
D(i,j) = D(i,j) + norm(imageStack(:,:,channel,i)-imageStack(:,:,channel,j));
end;
end;
end;
D = triu(D)+triu(D,1)';
Is there a way to do this without iteration?

댓글 수: 1

John BG
John BG 2016년 4월 2일
편집: John BG 2016년 4월 2일
have you tried
for i = 1:l
for j = i:l
D(i,j) = D(i,j) + norm(imageStack(:,:,:,i)-imageStack(:,:,:,j));
end;
end;
can you submit a sample of frames and channels?
also, functions bsxfun and arrayfun may have a way to combine the norm() and rid loops i and j.
There is an expert in this forum called Andrei Bobrov who showed me how to use bsxfun, may be you could ask him.

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 4월 2일

0 개 추천

Possibly reshape to rows, and then pdist() ?

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

질문:

2016년 4월 2일

편집:

2016년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by