Help using find function
15 views (last 30 days)
Show older comments
Hannah Rosenberg
on 5 Feb 2021
Commented: Hannah Rosenberg
on 8 Feb 2021
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);
0 Comments
Accepted Answer
Walter Roberson
on 5 Feb 2021
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)
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!