Find minimum in matrice

1 view (last 30 days)
Miguel Albuquerque
Miguel Albuquerque on 16 Jul 2022
Answered: patrick1704 on 16 Jul 2022
Hey guys, thanks in advance
I have this matrix, that always has zeros, but also other values. I want to find the minimum of the matrix, besides the zeros, how can I do that?

Accepted Answer

patrick1704 on 16 Jul 2022
If you only care about the value and not the index, you could do something like this:
min(R1_matrix(R1_matrix ~= 0))
If you care about the index you could do something like:
R1_matrix(R1_matrix == 0) = inf;

More Answers (1)

KSSV on 16 Jul 2022
Edited: KSSV on 16 Jul 2022
Let A be your matrix.
A(A==0) = NaN ; % replace 0's with NaNs
[val,idx] = min(A)
Or, use:
val = min(A(A>0))


Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!