MATLAB: Help using find function

findindexing

This is pretty basic but I'm just trying to properly get subcript indices after edge detection (logical matrix E). For some reason, linear indexing seems to be working, but whe I try to convert to subscript indices it goes all wrong. Any help would be appreciated.
indx = find(E);
mask=false(size(E));
mask(indx)=true;
imshow(mask);
[y,x] = ind2sub(size(E),indx);
mask=false(size(E));
mask(y,x)=true;
imshow(mask);

Best Answer

mask(y,x)=true;
That means the same as
for X = x
for Y = y
mask(Y, X) = true;
end
end
Which is to say that it sets all combinations of x and y.
It does not mean the same as
for index = 1 : length(y)
mask(y(index), x(index)) = true;
end
In order to do the operation you were hoping for, leave the indices as linear instead of breaking them out to row and column.
It looks to me as if the whole thing could be replaced with
mask = E ~= 0;
imshow(mask)