MATLAB: Assigning values ta set of points in 2d image

image processingMATLABmatrix array

After performing an operation on an image I get a set of points, the Cartesian coordinates are stored in a variable 'xy' of dimension n by 2. So xy(:,1) is x coordinate of each point and xy(:,2)is the y coordinate.
I want to create a new image of the same dimensions as the original image with these set of points being 1 and other points 0.
Let me create a problem to explain it further.
A = magic(10);
[x,y] = find(A<=20);
xy = [x,y];
B = zeros(size(A));
% now assign B as 1 for all points A<=20
Please help with the assignment command.
B(x,y) doesn't work i would like to know why ?

Best Answer

Then just do it this way:
A = magic(10)
[y,x] = find(A<=20);
% Note: y = rows, x = cols
B = zeros(size(A));
linearInd = sub2ind(size(A), y, x)
B(linearInd) = 1