Help using find function

14 ビュー (過去 30 日間)
Hannah Rosenberg
Hannah Rosenberg 2021 年 2 月 5 日
コメント済み: Hannah Rosenberg 2021 年 2 月 8 日
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);

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 5 日
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 件のコメント
Hannah Rosenberg
Hannah Rosenberg 2021 年 2 月 8 日
Thank you! The for loops were very helpful for explaining what's actually going on inside of those operations.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by