Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Sanghee
Posts:
6
Registered:
10/7/10


Arrary indexing with vectors ?
Posted:
Oct 26, 2010 10:55 AM


I have a quick task in the following.
TBL = round(rand([256,256])*63)+1; % An arrary has random numbers between 1 to 64
M = 2048;
X = round(rand(M)*255)+1; % Vector of size M with random number between 1 to 256 Y = round(rand(M)*255)+1; % Vector of size M with random number between 1 to 256
Now, I want to make an array Z which is a vector of size Mx1, where each entry has the one like,
Z(1) = TBL(X(1),Y(1)); Z(2) = TBL(X(2),Y(2)); ....
Certainly, I can use for loop like,
for j=1:M Z(j) = TBL(X(j),Y(j)); end
But, is there any way to do this with a simple vector operation ?




