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:
extracting one output vector from 3 input vectors into a 3-D array

Subject: extracting one output vector from 3 input vectors into a 3-D array

From: Joao Ejarque

Date: 14 Sep, 2012 12:35:08

Message: 1 of 2

Consider a 3-D array. Call it A1. Each dimension belongs to a variable (d1=>X1, d2=>x2, d3=>X3). Each element (i,j,k) of the A1 array specifies the transition of variable X1 from one period to the next.

I fact X1 is an index variable/vector with length equal to dimension 1 of A1, X2 is an index variable with length equal to the dimension 2 of A1, and X3 is an index variable with length equal to dimension 3 of A1.

There N individuals. Each individual n is described at any period t by 3 values of the 3 variables, Index(n,t) = (x1(n,t),x2(n,t),x3(n,t)). These 3 values are indices into the array A1, and when they are plugged into A1 produce the new value of x1(n,t+1) (itself an index).

The process is repeated for 2 other arrays, A2 and A3, which given the above input vector Index(n,t) produce the new values for individual n of x2(n,t+1) and x3(n,t+1).


What I need is a one line way to extract x1(n=1:N,t+1), for all N individuals simultaneously, using the A1 array, and 3 vectors Index(n=1:N,t) => x1(n=1:N,t) , x2(n=1:N,t) and x3(n=1:N,t)).

If I was working with 2 dimensions in A1, using a "diag" command - Indexout = diag(A1(index1in,index2in)) - gives me this easily. But with 3 dimensions I am not sure how to write it so that I dont have to loop.

Thank you

Joao Ejarque

Subject: extracting one output vector from 3 input vectors into a 3-D array

From: Matt J

Date: 14 Sep, 2012 13:58:08

Message: 2 of 2



A1(sub2ind( size( A1), x1(1:N,t), x2(1:N,t), x3(1:N,t) ))

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