I have a large 2D matrix, A
(8192x10201) and a list of coordinates, coord
(3622x2). I am trying to find the value of the array at each index and put it into a 1D list.
I could use the following for
loop, but I was wondering if there was a more elegant solution.
data = [];
for ii = 1:numel(coord(:,1))
data = [data; A(coord(ii,1), coord(ii,2)];
end
EDIT: Things I have tested:
1.data = A(coord)
data
is a 3622x2 matrix. I'm not certain how the values in data
relate to the coordinates in coord
.
2.data = A(coord(:,1), coord(:,2))
data
is 3622x3622 matrix. I am very much uncertain of how it relates to 'coord'.
Another way:
A(sub2ind(size(A), coord(:, 1), coord(:, 2)))