我想运行fminsearch函数来优化目标函数PARA。目标函数PARA是针对具有SxL像素的图像定义的,并且采用向量x(其为4x1)来返回每个像素的标量。我可以使用fminsearch进行S = 1和L = 1但是当S> 1或L> 1时,函数返回错误:
Subscripted assignment dimension mismatch.
Error in fminsearch (line 211)
fv(:,1) = funfcn(x,varargin{:});
Error in fminsearch_ESM (line 11)
[X(:,Si,Li),Fval(Si,Li)] = fminsearch(@ESM_PARA,[0;0;0;0]);`
下面列出了我用来为每个像素循环优化的代码片段。任何建议将不胜感激。
S=100;
L=100;
X = zeros(4,S,L);
Fval = zeros(S,L);
for Si=1:S
for Li=1:L
[X(:,Si,Li),Fval(Si,Li)] = fminsearch(@PARA,[0;0;0;0]);
end
end
目标函数PARA如下所列。
function f = PARA(x)
S=100;
L=100;
size(A11) = (3,3,S,L);
size(A22) = (3,3,S,L);
size(A12) = (3,3,S,L);
W=zeros(3,S,L);
W(1,:,:) = cos(x(1));
W(2,:,:) = sin(x(1))*cos(x(2))*exp(j*x(3));
W(3,:,:) = sin(x(1))*sin(x(2))*exp(j*x(4));
Xdd = zeros(S,L);
Dxi = zeros(S,L);
Dxj = zeros(S,L);
for Si=1:S
for Li=1:L
Xdd(Si,Li)=conj(W(:,Si,Li).')*A12(:,:,Si,Li)*W(:,Si,Li);
Dxi(Si,Li) = conj(W(:,Si,Li).')*A11(:,:,Si,Li)*W(:,Si,Li);
Dxj(Si,Li) = conj(W(:,Si,Li).')*A22(:,:,Si,Li)*W(:,Si,Li);
end
end
Axf = sqrt(Dxi.*Dxj);
f = abs(Xdd./Axf);
end