pick columns with a index vector

Hi I have a 30x100 data matrix and a 1x100 index vector with 1s in some columns and 0 elsewhere. How can I pick up columns in the data matrix corresponding to the 1s in the index vector. Thanks in advance.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 9일
편집: Azzi Abdelmalek 2014년 1월 9일

0 개 추천

%Example
A=rand(30,100)
B=randi([0 1],1,100)
%----------------------
out=A(:,logical(B))

댓글 수: 3

Linden
Linden 2014년 1월 9일
Doesn't work. Subscript indices must either be real positive integers or logicals.
thanks
Linden
Linden 2014년 1월 9일
Worked, thanks a lot.
Azzi Abdelmalek
Azzi Abdelmalek 2014년 1월 9일
Ok, then mark the answer as accepted

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

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2014년 1월 9일

댓글:

2014년 1월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by