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.

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 9 Jan 2014
Edited: Azzi Abdelmalek on 9 Jan 2014
%Example
A=rand(30,100)
B=randi([0 1],1,100)
%----------------------
out=A(:,logical(B))

3 Comments

Doesn't work. Subscript indices must either be real positive integers or logicals.
thanks
Worked, thanks a lot.
Ok, then mark the answer as accepted

Sign in to comment.

Categories

Asked:

on 9 Jan 2014

Commented:

on 9 Jan 2014

Community Treasure Hunt

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

Start Hunting!