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: accumarray: Unexpected behavior?
Replies: 3   Last Post: Dec 11, 2013 10:44 AM

Advanced Search

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

Posts: 17
Registered: 5/18/11
accumarray: Unexpected behavior?
Posted: Dec 10, 2013 2:22 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

From the 2012b doc and verified in Matlab:

val = 101:106;
subs=[1 2; 1 2; 3 1; 4 1; 4 4; 4 1];
B = accumarray(subs,val,[],@(x)sum(diff(x)))

B =

0 -1 0 0
0 0 0 0
0 0 0 0
2 0 0 0


Why is B(1,2) == -1? Shouldn't B(1,2) = sum(diff([101:102]))?

Just like B(4,1) = sum(diff([104;106])).



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.