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!