Find the indices of minimum value in each block of a block diagonal matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Stephen23
am 29 Jun. 2023
"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?
Antworten (1)
Stephen23
am 29 Jun. 2023
Bearbeitet: Stephen23
am 29 Jun. 2023
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 Kommentare
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!