How to extract all the elements in a vector whose index is 1?

조회 수: 1 (최근 30일)
Cantor Set
Cantor Set 2020년 2월 12일
편집: Adam Danz 2020년 2월 13일
Given a vector R:
R=[0.7 9 8 34 2]'; ranks=[1 2 2 2 3];
Where the first element in ranks crossponds to the rank of the first element in R and the second element in ranks crossponds to the second element in R and so on.
I need to extract all the elements whose ranks are 2 and put them in a vector but I need a general way because the sizes of the vectors R and ranks will vary
I appreciate your help
thank you

답변 (1개)

Adam Danz
Adam Danz 2020년 2월 12일
편집: Adam Danz 2020년 2월 13일
x = R(ranks == 2)
Indexing is one of the most important tools in Matlab. This is a good resource to get you started.

카테고리

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