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 ]
Daniel

Posts: 12
Registered: 9/29/12
How to vectorize this matrix indexing
Posted: Dec 28, 2012 8:14 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hello,

Does anyone have an idea on vectorizing the for loop in the following program?

A=rand(10,4)
b=[2 4 1 3 2 3 1 2 4 1]'
r=zeros(10,1);

for m=1:10
r(m)=A(m,b(m));
end

'b' is an index array for selecting a certain column. The index is different for different rows. Any suggestions? Thanks.

Daniel



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.