MATLAB: I need help in matlab code fort he least squares estimators of the parameter of auto regressive model

ar-2dimage processingtexture analyse

i need to Compute the coefficient teta of parameter of the AR-2D model described by:
X(i,j)=teta(1,0)*X(i-1,j)+teta(0,1)*X(i,j-1)+e(i,j)
X it is blocks of image
i=imread('D1.gif');
i= im2double(i);
x = imresize( i,0.25);
[m,n] = size(x);
noise=randn(size(x));
X = mat2cell(x, 80 * ones(1,m/80), 80 * ones(1,n/80));
**this the function**
function [teta,k] =ls( X,x,noise)
global m n
global R C
p1=1;
p2=1;
% for r = 1+p1 : R
% for c = 1+p2 : C
for i=1+p1:R
for j=1+2:C
X(i,j)= teta(1,0)*X(i-1,j)+teta(0,1)*X(i,j-1)+noise(i,j);
X=X+1;
end
end
teta= (inv(x'*X))*(x'*X)
end
i have problem in this function

Best Answer

you are using teta as a function when you invoke teta(1,0) . We know that because there is no assignment to teta before that point and using 0 as an index is not possible . So teta must be a function .
But at the end of the function you assign to teta as a variable . This is confusing .
Your function can only work if four global variables have been assigned to . You do not do those assignments . You assign to variables m and n in your script but they are not global variables in the script .
But bugs in the function do not matter since you never call the function .
Related Question