필터 지우기
필터 지우기

collect rows of a matrix having a desired number in the first row

조회 수: 1 (최근 30일)
Christopher
Christopher 2014년 11월 21일
댓글: Azzi Abdelmalek 2014년 11월 21일
If I have a matrix, what is the fastest way to collect the columns which satisfy a logical operation in the first row?
So if I have the matrix
0 5 3 6 4 5 8 4 7 5 1
5 6 7 5 6 7 8 9 4 5 2
3 4 3 5 8 3 5 4 4 5 1
9 6 7 1 6 3 7 4 5 3 8
9 2 9 5 0 4 2 5 6 3 4
if I wanted to collect all rows which have a 5 in the first row I would have
5 5 5
6 7 5
4 3 5
6 3 3
2 4 3
It is important that it is as fast as possible.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 21일
편집: Azzi Abdelmalek 2014년 11월 21일
A=[0 5 3 6 4 5 8 4 7 5 1
5 6 7 5 6 7 8 9 4 5 2
3 4 3 5 8 3 5 4 4 5 1
9 6 7 1 6 3 7 4 5 3 8
9 2 9 5 0 4 2 5 6 3 4]
B=A(:,A(1,:)==5)
  댓글 수: 2
Christopher
Christopher 2014년 11월 21일
Sorry I made a mistake. How, instead, do I get the following index from the original matrix:
0 1 0 0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0 0 1 0
0 1 0 0 0 1 0 0 0 1 0

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by