Help using find function

14 visualizaciones (últimos 30 días)
Hannah Rosenberg
Hannah Rosenberg el 5 de Feb. de 2021
Comentada: Hannah Rosenberg el 8 de Feb. de 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);

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de Feb. de 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)
  1 comentario
Hannah Rosenberg
Hannah Rosenberg el 8 de Feb. de 2021
Thank you! The for loops were very helpful for explaining what's actually going on inside of those operations.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by