Optimal distance calculation for a data cube
1 次查看(过去 30 天)
显示 更早的评论
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
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!