Цитата:
я бы сначала объявлял global M, а уже потом инициализировал,
спасибо за совет так и сделал
попробуйте запустить функцию используя
это изображение:
Код:
function sol=es()
global M;
X=2;
M=imread('Ttext1.tif');
[a b]=size(M);
for v=1:a
for w=1:b
if ( M(v,w) == 1 )
M;
%[x y]=find(M==1);
%[xn yn]=max([x y]);
find_pattern(v,w,X);
X=X+1;
end
end
end
sol=M;
Код:
function z=find_pattern(i,j,X)
global M;
if( M(i,j) == 1 )
M(i,j)= X;
if M(i-1,j)==1 z=feval('find_pattern',i-1,j,X); end
if M(i+1,j)==1 z=feval('find_pattern',i+1,j,X); end
if M(i,j-1)==1 z=feval('find_pattern',i,j-1,X); end
if M(i,j+1)==1 z=feval('find_pattern',i,j+1,X); end
if (M(i-1,j)-1) & (M(i+1,j)-1) & (M(i,j-1)-1) & (M(i,j+1)-1)
z=M;
end
z=M;
end
у меня выдает в конце:
Код:
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In find_pattern at 17
In find_pattern at 18
In es at 43
??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in ==> find_pattern at 18
if M(i+1,j)==1 z=feval('find_pattern',i+1,j,X); end