フィルターのクリア

Is there is a way I can select the minimum value from a matrix, and replace all numbers surrounding this minimum value (3 cells) by a specific number

1 回表示 (過去 30 日間)
I want to select this minimum value cell, and anything within a radius of ‘less than or equal to’ three cells to be replaced with a specific number such as 99 (including the selected minimum cell).
I have uploaded a pdf of what i am trying to accomplish. Sorry for any inconvenience and thank you.

採用された回答

dpb
dpb 2013 年 11 月 9 日
編集済み: Andrei Bobrov 2013 年 11 月 10 日
[~,imin]=min(x(:)); % location of min (linear
[im,jm]=ind2sub(size(x),imin); % convert to subscripts
x(im-1:im+1,jm-1:jm+1)=99; % set a square around that location
  6 件のコメント
Ruby
Ruby 2013 年 11 月 11 日
Regarding the 'setting a square perimeter' around the min value, if the min value is in either column 1 or row 1, it shows an error message. This is because there are no numbers around the edge of the matrix so it cant set them as 99. Is there any way around this error?
dpb
dpb 2013 年 11 月 11 日
You'll have to write logic to handle the condition; there's no automagic way that I can think of. Wrapping the bounds expressions inside min and max is one way can do that so that, for instance, the LHS x-bound becomes
max(im-1,1)
Similar logic w/ proper limits for the other directions should be obvious extension. The end keyword is invaluable in such instances for upper bound values, btw...

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by