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: index end-point to matrix
Replies: 6   Last Post: Feb 4, 2013 11:24 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 9,042
Registered: 7/26/08
Re: index end-point to matrix
Posted: Feb 1, 2013 9:04 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

k = b > 0;
c = b(k);
l = diff([0 c]);
s = c(end);
c(end) = [];
i = zeros(1,s);
i(c+1) = 1;
i = 1+cumsum(i);
j = ones(1,s);
j(c+1) = 1-l(1:end-1);
j = cumsum(j);
a = zeros(length(b), max(j));
a(k,:) = accumarray([i(:) j(:)], (1:s)')

% Bruno

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

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.