Indexing matrix from array

1 次查看(过去 30 天)
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,:);

更多回答(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