Hi,
I have A = [1:3; 4:6; 7:9] and an index B = [1;0;1].
How can I extract from each column of A the values at are equal to 1 in B?
I want C = [1:3;7:9]. (I am trying to avoid having to use repmat for B)
Thank you!
IP

 채택된 답변

David Hill
David Hill 2022년 3월 25일

0 개 추천

A = [1:3; 4:6; 7:9];
B = logical([1;0;1]);
C=A(B,:);

댓글 수: 1

Inna Pelloso
Inna Pelloso 2022년 3월 25일
Thank you! I forgot to format the index as logical!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2022년 3월 25일

댓글:

2022년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by