限制最小二乘回归的范围

时间:2017-03-12 13:06:34

标签: matlab regression least-squares

我想对一组数据A(k1,k2)进行回归,但我希望将回归限制在-K1<k1<K1-K2<k<K2的范围内。 A是由60x60矩阵组成的图像阶段,其维度为MxN。从A的归一化频率区域的中心以0.1N / 2进行最小二乘近似。

这是代码的一部分:

A=rand(60);
[m, n]=size(A);
[M,N] = meshgrid(1:m,1:n);
X = [M(:), N(:)];
B=regress(A(:), X);  %regression will be done on all the values of A, part where adjustment needed
hat=reshape(X*B,m,n);

1 个答案:

答案 0 :(得分:1)

您可以先选择要执行回归的矩阵子集:

% generate the full image
A_full=rand(60);
[m, n]=size(A_full);

% select the part you want, 
% it is not very clear to me if this is really the part you want, 
% but I think you will be able to change it to your needs
A=A_full(floor(m/2-0.1*m/2):ceil(m/2+0.1*m/2), floor(n/2-0.1*n/2):ceil(n/2+0.1*n/2)); 

% perform the regression on the selected part of A (like you did it)
[m, n]=size(A);
[M,N] = meshgrid(1:m,1:n);
X = [M(:), N(:)];
B=regress(A(:), X);  %regression will be done on all the values of A, part where adjustment needed
hat=reshape(X*B,m,n);