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 vectorize this matrix indexing
Replies: 1   Last Post: Dec 28, 2012 8:27 AM

Advanced Search

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

Posts: 2,923
Registered: 10/6/08
Re: How to vectorize this matrix indexing
Posted: Dec 28, 2012 8:27 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Dear Daniel,

A = rand(10,4);
b = [2 4 1 3 2 3 1 2 4 1];
r = A(sub2ind(size(A), 1:10, b));

See: http://www.mathworks.com/help/matlab/ref/sub2ind.html

Kind regards, Jan



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.