matrix buffer

1 回表示 (過去 30 日間)
M.J. Glasbergen
M.J. Glasbergen 2012 年 2 月 4 日
編集済み: Matt J 2013 年 10 月 4 日
I've got a large matrix, mainly consisting of zeros and with some randomly placed values. I would like to be able to find the surrounding zeros of the non-zero values. If a single value is only surrounded by zeros it's no problem, but a cluster of values poses more problems. I could treat the values in the cluster as single values, but that means an extremely long runtime of the code. Is there a way to find all zeros surrounding a certain value? I don't have any additional toolboxes, but if there is one that could be usefull, I can always try to convince my boss that I need it...

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 2 月 4 日
bwdist from Image Processing Toolbox
OR
A - your array
[i1,j1] = find(A)
[y x] = ndgrid(1:size(A,1),1:size(A,2))
out = min(max(abs(bsxfun(@minus,x,reshape(j1,1,1,[]))),...
abs(bsxfun(@minus,y,reshape(i1,1,1,[])))),[],3)
  4 件のコメント
Andrei Bobrov
Andrei Bobrov 2012 年 2 月 8 日
more variant
out = min(hypot(bsxfun(@minus,y,permute(i1,[3 2 1])),bsxfun(@minus,x,permute(j1,[3 2 1]))),[],3)
as 'bwdist' from 'Image Processing Toolbox'
M.J. Glasbergen
M.J. Glasbergen 2012 年 2 月 10 日
You're the greatest, this last one is the one I was looking for now :-)

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

その他の回答 (1 件)

M.J. Glasbergen
M.J. Glasbergen 2012 年 2 月 5 日
Seems to work great, thnx!

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by