how to pull out indicies from a matrix

조회 수: 2 (최근 30일)
Christian Candler
Christian Candler 2020년 4월 6일
댓글: Christian Candler 2020년 4월 6일
I have a matrix which is essestially two vectors. It looks something like:
Row 1: 1,2,1,2,1,2,1,2,1,2.........
Row 2: 132.2, 132.7, 133.5...........
I want to pull out the indexes that correspond under all of the ones and twos into another vector. I've done something like:
A(A ==1) so it pulls out all of the 1s, but I want it to pull the values in the row underneath the 1 as well.

채택된 답변

KSSV
KSSV 2020년 4월 6일
Let A be your 2*m matrix...
r1 = A(1,:) ;
r2 = A(2,:) ;
iwant = r2(r1==1)
iwant = r2(r1==2)
From matrix directly.
iwant = A(:,A(1,:)==1)
iwant = A(:,A(1,:)==2)
  댓글 수: 1
Christian Candler
Christian Candler 2020년 4월 6일
Oh perfect, still getting used to the thought process for Matlab problems. Thanks so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by