필터 지우기
필터 지우기

finding min matrix and where that is

조회 수: 1 (최근 30일)
bachelor student
bachelor student 2016년 8월 10일
댓글: Star Strider 2016년 8월 10일
Hi all I have a matrix, I want to find its minimum and where that minimum is, can anybody help me with that?

답변 (1개)

Star Strider
Star Strider 2016년 8월 10일
This works to find the first minimum:
M = randi(9, 5); % Create Matrix
[Mmin,lidx] = min(M(:));
[r,c] = ind2sub(size(M),lidx);
Result = [Mmin r c]
If there are mor than one values of the minimum:
M = randi(9, 5); % Create Matrix
Mmin = min(M(:))
[r,c] = find(M == Mmin)
  댓글 수: 3
bachelor student
bachelor student 2016년 8월 10일
there is just one problem, i want to find the min, except for the zero values
Star Strider
Star Strider 2016년 8월 10일
My pleasure.
To get the minimum value and locations for all values not equal to zero, this works:
M = randi([0 5], 5); % Create Matrix
Mmin = min(M(M(:) ~= 0))
[r,c] = find(M == Mmin)
(This also allows for negative values in the matrix if necessary, even though the test matrix values go from 0 to 5 here.)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by