How can I implement this without using for loops?
for i = 1:i_rows Mat_NX3(i,1) = (Mat_A_3D (idx(i,1), idx(i,2), 1) ); Mat_NX3(i,2) = (Mat_A_3D (idx(i,1), idx(i,2), 2) ); Mat_NX3(i,3) = (Mat_A_3D (idx(i,1), idx(i,2), 3) ); end
where:
- Mat_NX3 is the output N X 3 matrix
- Mat_A_3D is a 3D matrix
- idx is a matrix with 2 columns, (index points) telling which co-ordinate values should be copied from Mat_A_3D into Mat_NX3. It has i_rows number of rows
Example if
Mat_A_3D (:,:,1) = [1 2 3 4 5 6 7 8 9];Mat_A_3D (:,:,2) = [1 2 3 4 5 6 7 8 9];Mat_A_3D (:,:,3) = [1 2 3 4 5 6 7 8 9];
and
idx = [1,1 3,3];
output
Mat_NX3 = [1 1 1; 9 9 9];
Best Answer