Finding values in a matrix with logical operation

조회 수: 1 (최근 30일)
MiauMiau
MiauMiau 2013년 1월 9일
Hi
I know how to show for a Matrix A the values in the first column which fullfill a certain condition. Say:
A =
8 1 6
3 5 7
4 9 2
Then I could use for displaying all the values bigger then 3 in the first column the following line:
A(A(:,1) > 3)
But what line do I use, if I want to display the values in the second column which are bigger than say "3"?
Thanks
  댓글 수: 1
Matt J
Matt J 2013년 1월 9일
편집: Matt J 2013년 1월 9일
Then I could use for displaying all the values bigger then 3 in the first column the following line: A(A(:,1) > 3)
While this would work in the case of the first column, it is cleaner to specify the column number explicitly not just in the indexing expression, but also in the look-up expression
A(A(:,1) > 3, 1 )
It's also easier to see how to generalize it to other columns, as Jan has showed you.

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

채택된 답변

Jan
Jan 2013년 1월 9일
편집: Jan 2013년 1월 9일
A strange question. What about replacing the column index 1 by 2?
A(A(:, 2) > 3, 2)
Explicitly:
v = A(:, 2);
v(v > 3)
  댓글 수: 1
MiauMiau
MiauMiau 2013년 1월 9일
sorry for the strange question. I was not aware that it is possible to use booleans in that way, since A(:,2) > 3 in our case returns a boolean 3,1-Matrix, whereas the index for the column is just the 1,1 matrix "2". That's not so obvious to come up with for a beginner.

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

추가 답변 (0개)

카테고리

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