Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Extracting portions of matrix into cell array
Posted:
Mar 25, 2013 8:40 PM


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.)



