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: How to a 1-D matrix into several 1-D matrix based on condition
Replies: 5   Last Post: Dec 8, 2012 4:36 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
james bejon

Posts: 214
Registered: 3/13/10
Re: How to a 1-D matrix into several 1-D matrix based on condition
Posted: Dec 8, 2012 4:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Can't test this, but if you want a vectorized version:

A = [1 3 5 7 8 1 4 0 1 4 6 3 0 0 1 4 6 0 0 0 2 5 9 1].';
Z = find(A == 0);
Z = Z(diff([0; Z]) ~= 1);
S = zeros(length(A), 1);
S(Z) = 1;
S = cumsum(S)+1;
X = accumarray(S, A, [], @(x) {x})



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.