Minimum value,row and column

조회 수: 156 (최근 30일)
Giannakis Stoukas
Giannakis Stoukas 2015년 4월 15일
댓글: Image Analyst 2017년 6월 11일
I want to find the minimum value of a matrix,the row and the column of it

답변 (3개)

Jan
Jan 2015년 4월 16일
편집: Jan 2015년 4월 16일
[value, index] = min(A(:));
[row, col] = ind2sub(size(A), index);
In opposite to the solution of Image Analyst, this is faster, but considers only one value even if the minimal value appears multiple times in the array.
  댓글 수: 12
Mahbubur Rahman
Mahbubur Rahman 2016년 4월 30일
Hi, thanks again. Your answer is okay. But problem is how do I relate the lowest row for the lowest column.
A = [1 1 7 1 8; 2 4 5 9 5; 6 5 0 2 3; 3 7 5 1 9; 9 5 2 6 7]
[r c]= find(A==5);
You can see that the lowest number of c is 2. And for this c = 2, we get two r (3 and 5). Now I want to select the r_min for c_min (which is c=2). My answer should be (2,3). Just figured out that If I make a matrix
B=[c r];
Answer = B(1,:)
It gives me the desired value. Comment please.
Image Analyst
Image Analyst 2016년 4월 30일
It's the same solution I've been telling you. Now I've renamed minA to valueToFind since it appears that you're not always looking to find the min values. And since you want an (x,y) answer rather than "value of the row" like you asked for before I just concatenate them together:
A = [1 1 7 1 8; 2 4 5 9 5; 6 5 0 2 3; 3 7 5 1 9; 9 5 2 6 7]
% valueToFind = min(A(:)); % Find the min value of A
valueToFind = 5;
[row, column] = find(A == valueToFind)
MyAnswer = [column(1), row(1)] % In format [x,y] NOT [row, column]
You can call it MyAnswer, or B, or whatever you want, but I'd probably not use Answer.

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


Image Analyst
Image Analyst 2015년 4월 15일
Here's one way:
minValue = min(yourArray(:));
[row, column] = find(yourArray == minValue);
  댓글 수: 3
Image Analyst
Image Analyst 2015년 4월 15일
You could run down row by row inverting the lines and then use findpeaks() in the Signal Processing Toolbox. Probably far less efficient than the first way.
You could use imregionalmin() in the Image Processing Toolbox.
There are other ways I'm sure, such as functions in the various optimization toolboxes.
Giannakis Stoukas
Giannakis Stoukas 2015년 4월 15일
I will do it the easy way then,thanks

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


Kaelan Wade
Kaelan Wade 2017년 6월 11일
Can't you just go
  • A = some matrix
  • [row,collum] = find(A == min(min(A)))
  • min_val = S(row,collum)
  댓글 수: 1
Image Analyst
Image Analyst 2017년 6월 11일
Yes, you can. In fact that's what my answer up above already said, though in a more efficient way. You don't need to use min twice if you use (:) and your way gives an array of all the same min value whereas most likely only a single value is needed, even if the min shows up multiple times.

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

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by