2017-03-12 58 views
0

我想對一組數據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

您可以先選擇您要執行的迴歸你的矩陣的子集:

% 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); 
+0

出於好奇,是有可能讓所有'k2'值保持所有'k1'值爲零,'A(k1,0)'? –

+0

是的,只需將A定義爲A = A_full(floor(m/2-0.1 * m/2):ceil(m/2 + 0.1 * m/2),floor(n/2));'I假設'k2 = 0'對應矩陣的中間值,但情況可能並非如此。 (在MATLAB中不存在索引0) – m7913d

+0

啊我看到了,謝謝你的幫助! –