# 1 -, imdilate, -
A(imdilate(A,[ones(1,4) zeros(1,4+1)])==1)=2
# 1: , imdilate -
morph_strel = [ones(1,4) zeros(1,4+1)]
, n n , .
# 2: imdilate, A , 1 1 A -
imdilate_result = imdilate(A,morph_strel)
№ 3: 1 A 2 -
A(imdilate_result==1)=2
, : -
A(imdilate(A,[ones(1,window_length) zeros(1,window_length+1)])==1)=new_value
where window_lengthwill be 4, and new_valuewill be 2for the data.
Approach # 2 Use - bsxfun
%// Paramters
window_length = 4;
new_value = 2;
B = A' %//'
[r,c] = find(B)
extents = bsxfun(@plus,r,-window_length:-1)
valid_ind1 = extents>0
jump_factor = (c-1)*size(B,1)
extents_valid = extents.*valid_ind1
B(nonzeros(bsxfun(@plus,extents_valid,jump_factor).*valid_ind1))=new_value
B = B' %// B is the desired output
source
share