match elements of a matrix to an array
2 views (last 30 days)
I have one matrix (A1) of size 4000x8000 and the second matrix (g1) of size 100000x2.
I am trying to match each number in A1 to the nearest number in g1(:,1) and build another matrix (xxx) witn the corresponding element in g1(:,2).
I am tring the following however I get an error
Error using bsxfun
Requested 50001x37324800 (6952.4GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause
MATLAB to become unresponsive.
The following process works for smaller matrices.
Any help is much appreciated.
s=A1(:)';%%converting A1 to n array
[~,minRow] = min(abs(bsxfun(@minus,g(:,1),s)));
xxx = [ s.', g(minRow,2:end) ];