필터 지우기
필터 지우기

Indexing matrix from array

조회 수: 1 (최근 30일)
Inna Pelloso
Inna Pelloso 2022년 3월 25일
댓글: Inna Pelloso 2022년 3월 25일
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일
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개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by