MATLAB Answers

The minimum value of a matrix array and its index

4 views (last 30 days)
Hello everybody,
I want to get a single minimum value of a matrix and know its index.What shold I do?
Thank you very much

  0 Comments

Sign in to comment.

Accepted Answer

Bastian Arturo Romero Mardones
Edited: Bastian Arturo Romero Mardones on 15 Nov 2020
A = rand(1,5); %example matrix
[mini,index] = min(A) %mini= minimum value, index = index of minimum value
or
A = rand(5) %example 5x5 matrix
[minRow,indexRow]=min(A)
[minCol,indexCol]=min(minRow)
index = [indexRow(indexCol) indexCol] %minimum value o 5x5 matrix (row index, column index)
A = rand(5)
[M,I] = min(A(:));
[I_row, I_col] = ind2sub(size(A),I);
index = [I_row I_col]

  1 Comment

MOHAMED ABDULAZIM
MOHAMED ABDULAZIM on 20 Nov 2020
Thank you very much,Bastian Arturo Romero Mardones.

Sign in to comment.

More Answers (0)

Products


Release

R2013a

Community Treasure Hunt

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

Start Hunting!