Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Extracting portions of matrix into cell array
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
paulcmnt

Posts: 1
Registered: 3/25/13
Extracting portions of matrix into cell array
Posted: Mar 25, 2013 8:40 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I have a pretty large matrix `M` and I am only interested in a few of the columns. I have a boolean vector `V` where a value of `1` represents a column that is of interest. Example:

> M =
> 1 1 1 7 7 1 1 1 7 7 7
> 1 1 7 7 7 1 1 7 7 7 7
> 1 1 7 7 7 1 1 1 7 7 1
>
> V =
> 0 0 1 1 1 0 0 1 1 1 1



If multiple adjacent values of `V` are all `1`, then I want the corresponding columns of `M` to be extracted into another matrix. Here's an example, using the matrices from before.

> M1 =
> 1 7 7
> 7 7 7
> 7 7 7
>
> M2 =
> 1 7 7 7
> 7 7 7 7
> 1 7 7 1


How might I do this efficiently? I would like all these portions of the matrix `M` to be stored in a cell array, or at least have an efficient way to generate them one after the other. Currently I'm doing this in a while loop and it is not as efficient as I'd like it to be.

(Note that my examples only include the values `1` and `7` just for clarity; this isn't the actual data I use.)



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.