line and column of the minimun element of a matrix

조회 수: 1 (최근 30일)
Opariuc Andrei
Opariuc Andrei 2021년 1월 16일
편집: Jan 2021년 1월 16일
how do i find the position (line and column of the minimun element of a matrix)
i have a matrix
m=
[5 1 -400;
-6 100 -6;
2 5 25];
how can i get matlab to give me the position of -400 ? line 1 column 3

채택된 답변

Jan
Jan 2021년 1월 16일
편집: Jan 2021년 1월 16일
m = [5 1 -400; ...
-6 100 -6;
2 5 25];
[~, ind] = min(m(:));
[row, col] = ind2sub(size(m), ind)
Or:
[v, ind1] = min(m, [], 1); % Along 1st dimension
[~, col] = min(v, [], 2); % Along 2nd dimension
row = ind1(col)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Test and Measurement에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by