How can I get a row vector where a specific element found is located within a matrix?
조회 수: 5 (최근 30일)
이전 댓글 표시
I am trying to write a program that gives a row vector from a matrix that has the lowest element from a specific column. For example, say if I have the following,
A =
2009 8 2 4
2010 3 4 5
2011 6 9 1
2012 1 3 7
If I want to find the smallest value in column 3, which is 2, how do I get MATLAB to give the row where it is found, so that the result is
ans =
2009 8 2 4
I have been struggling with this for the past 2 days and I feel like because I've stared at this for so long I can't spot the problem. Can I get some help please?
댓글 수: 0
채택된 답변
Andrei Bobrov
2012년 10월 10일
편집: Andrei Bobrov
2012년 10월 10일
A =[
2009 8 2 4
2010 3 4 5
2011 6 9 1
2012 1 3 7];
[ii,ii] = min(A(:,3));
out = A(ii,:);
or
out = A(abs(A(:,3) - min(A(:,3))) < eps(100),:);
댓글 수: 0
추가 답변 (1개)
Erika
2012년 10월 10일
댓글 수: 3
Andrei Bobrov
2012년 10월 10일
편집: Andrei Bobrov
2012년 10월 10일
Hi Matt! Second part in my answer?(after 'or')
Matt Tearle
2012년 10월 15일
Oh, yes, you're right -- I was a bit confused by the eps and didn't look too closely.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!