Find the indices of minimum value in each block of a block diagonal matrix
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 29 de Jun. de 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?
Respuestas (1)
Stephen23
el 29 de Jun. de 2023
Editada: Stephen23
el 29 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!