Find the indices of minimum value in each block of a block diagonal matrix
3 次查看(过去 30 天)
显示 更早的评论
I have a 1164x1170 matrix that is mostly NaNs except for blocks of values on the diagonal. They are not in blocks of predictable size.
I want to know the indices of the minimum value in each block. I wanted to use mat2cell but I don't know the size of the blocks ahead of time.
Edit: I have attached my data matrix as a .mat - also a version of it with zeros instead of NaNs
4 个评论
Stephen23
2023-6-29
"I guess I could do a for loop over this number with the labels to try and find the minima?"
That is what my code does. Did you try it?
回答(1 个)
Stephen23
2023-6-29
编辑:Stephen23
2023-6-29
Using BWLABEL as KSSV suggested:
S = load('synced_stamped.mat');
M = S.synced_stamp
M(isnan(M)) = 0;
[X,N] = bwlabel(M,4)
F = @(n)myfun(M,n==X);
Z = arrayfun(F,1:N) % linear indices
[R,C] = ind2sub(size(M),Z) % optional subscript indices
function Z = myfun(M,X)
[~,I] = min(M(X));
Y = find(X);
Z = Y(I);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!