Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Mathematics
General TopicsResearchOperations ResearchStatisticsMathematical LogicNumerical AnalysisUndergraduate MathAlgebra HelpRecreational Math
Math Software
MapleMathematicaMATLABScilabSASSPSS

Math Forum / Math Software / MATLAB / July 2008



Tip: Looking for answers? Try searching our database.

accessing multiple elements of matrix

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alistair Templeton - 16 Jul 2008 23:29 GMT
So I have a matrix A.
Elsewhere in my code I generate a vector x and vector y, for
example

x = [1 4 2]
y = [8 2 4]

what I'd like to do is recover the elements
A(1,8)
A(4,2)
A(2,4)

Is there a cleaner way to do this than something along the
lines of:

A(x+(y-1)*size(A,1))
Walter Roberson - 16 Jul 2008 23:46 GMT
>x = [1 4 2]
>y = [8 2 4]

>what I'd like to do is recover the elements
>A(1,8)
>A(4,2)
>A(2,4)

A(sub2ind(size(A),x,y))
Signature

 "Product of a myriad various minds and contending tongues, compact of
 obscure and minute association, a language has its own abundant and
 often recondite laws, in the habitual and summary recognition of
 which scholarship consists."                -- Walter Pater

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.