Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Calling points in an array with vectors

Subject: Calling points in an array with vectors

From: Justin

Date: 31 Oct, 2011 05:14:11

Message: 1 of 3

Ok here's what I want to do. Basically, I have an array A and two vectors x and y where x = [1 3 2] and y = [5 6 9]. I want to do something like A(x,y) where the points (1,5), (3,6), and (2,9) are called. But, when I entered the vectors as such, it calls all permutations of (1,5), (3,6),and (2,9), although the points for the aforementioned coordinates are located along the diagonal. Anyone have any ideas how I'd go about doing this preferably without a for loop. Thanks a bunch,

-Justin

Subject: Calling points in an array with vectors

From: Roger Stafford

Date: 31 Oct, 2011 06:27:10

Message: 2 of 3

"Justin " <jstain@gmail.com> wrote in message <j8lar3$5h7$1@newscl01ah.mathworks.com>...
> Ok here's what I want to do. Basically, I have an array A and two vectors x and y where x = [1 3 2] and y = [5 6 9]. I want to do something like A(x,y) where the points (1,5), (3,6), and (2,9) are called. But, when I entered the vectors as such, it calls all permutations of (1,5), (3,6),and (2,9), although the points for the aforementioned coordinates are located along the diagonal. Anyone have any ideas how I'd go about doing this preferably without a for loop. Thanks a bunch,
>
> -Justin
- - - - - - - - - -
 v = A(x+size(A,1)*(y-1));

or use 'sub2ind'.

Roger Stafford

Subject: Calling points in an array with vectors

From: Justin

Date: 2 Nov, 2011 17:49:28

Message: 3 of 3

"Roger Stafford" wrote in message <j8lf3u$gv9$1@newscl01ah.mathworks.com>...
> "Justin " <jstain@gmail.com> wrote in message <j8lar3$5h7$1@newscl01ah.mathworks.com>...
> > Ok here's what I want to do. Basically, I have an array A and two vectors x and y where x = [1 3 2] and y = [5 6 9]. I want to do something like A(x,y) where the points (1,5), (3,6), and (2,9) are called. But, when I entered the vectors as such, it calls all permutations of (1,5), (3,6),and (2,9), although the points for the aforementioned coordinates are located along the diagonal. Anyone have any ideas how I'd go about doing this preferably without a for loop. Thanks a bunch,
> >
> > -Justin
> - - - - - - - - - -
> v = A(x+size(A,1)*(y-1));
>
> or use 'sub2ind'.
>
> Roger Stafford


Thank you roger!!!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us