Mask unwanted data with zeros

10 ビュー (過去 30 日間)
bugguts99
bugguts99 2011 年 6 月 3 日
回答済み: Madhava Teja Munagala 2018 年 2 月 25 日
I have a matrix of dimensions 9634 x 80. I have a number of quality flags where I would like to mask the 'bad' data with zeros. I have created a mask where:
mask = zeros(size(data));
I have identified parts of this matrix where this occurs (for example, row and columns using:
[r, c] = find(idx > 0);
How then do I clear the contents of entire row and not just those cells where the quality flag is located?

採用された回答

Walter Roberson
Walter Roberson 2011 年 6 月 3 日
After you have done the above,
data(r,:) = 0;
if you want to clear it in the data. If you want to instead build a mask in which 0 indicates data to be ignored and 1 indicates data to keep, then start with
mask = ones(size(data));
and then to mask off the rows listed in r,
mask(r,:) = 0;
  1 件のコメント
bugguts99
bugguts99 2011 年 6 月 3 日
Thanks Walter!

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

その他の回答 (2 件)

Madhava Teja Munagala
Madhava Teja Munagala 2018 年 2 月 24 日
編集済み: Walter Roberson 2018 年 2 月 24 日
mask = zeros(size(i));
mask(25:end-25;25:end-25)=1;
imshow(mask);
May i know wat exactly 25:end-25 specifies
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 2 月 24 日
end designates the size of the array in that dimension. So M(25:end-25;25:end-25) is the same as M(25:size(M,1)-25,25:size(M,2)-25)
What the code is doing is creating a matrix of 0 and then painting most of the inside with 1. The part that is left as 0 is a border that is 24 pixels wide from the left, 25 pixels wide from the right, 24 pixels high from the top, and 25 pixels wide from the bottom.
It is fairly likely that the person who coded it thought that they were leaving a border of 25 at the top and left, but did not use the correct index for that, and further it is likely that they only accidentally got the 25 on the right and bottom, that if they had corrected the border that they would have made a mistake on the bottom and right.
If you want a border N wide then the index should be N+1:end-N

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


Madhava Teja Munagala
Madhava Teja Munagala 2018 年 2 月 25 日
thank you walter roberson sir

カテゴリ

Help Center および File ExchangeAuthor Block Masks についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by