Having the following code in Matlab:
r= zeros(10,10);
r(:) = x(z);
given that "x" is a single dimension array and "z" is a 2d array what is the function
r(:) = x(z); doing and how could I implement something similar in Java?
Having the following code in Matlab:
r= zeros(10,10);
r(:) = x(z);
given that "x" is a single dimension array and "z" is a 2d array what is the function
r(:) = x(z); doing and how could I implement something similar in Java?
Firstly, x(z) takes each element in the 2d-array z, and uses it as an index to fetch data from x.
For example x=[1 2] z = [1 1; 1 2] would give the result x(z) = [1 1; 1 2] because x(z) is really [x(z(1,1)) x(z(1,2)); x(z(2,1)) x(z(2,2))]. Therefore you have to be careful that the values in z doesn't exceed the size of x or you'll get index out of bounds.
r(:) = x(z) is basically the same as r = x(z).
To implement this in java you would need som kind of for-loop over the elements in z. In this loop you would construct a 2d-array by assigning the current index (i,j) with the value in x(z(i,j)).
Hope this helps!