Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Combining separate files

2 ビュー (過去 30 日間)
buxZED
buxZED 2011 年 3 月 2 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
??? Subscripted assignment dimension mismatch.
Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});
Error in ==> p5final at 95
sig4=fminsearch('P5F',1.5);% minimse the cost function using 'fminsearch' giving
a predicted value for sigma4
i get this error for the coding
sig4=fminsearch('P5F',1.5);% minimse the cost function using 'fminsearch' giving a predicted value for sigma4
c44=exp(-z.^2/(2*(sig4)^2));% Use global value for 'z' and predicted value for sigma4 to find a forth predicted value for average plume concentration ratio 'c'
e4=c-c44;% calculate prediction error between global c (average plume concentration ratio) and the forth predicted plume concentration
>> P5F is a another file codes are
function J=P5F(Sig)
global c2 z
J=0;
for k=1:201;
s1=c2*(k);
s2=exp(-z(k)^2/(2*(Sig)^2));
J=J+(s1-s2)^2;
end

回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 3 月 2 日
The argument to fminsearch must be a function handle, not a string. Use @P5F instead of 'P5F'
  2 件のコメント
buxZED
buxZED 2011 年 3 月 2 日
still gives the same error
?? Subscripted assignment dimension mismatch.
Error in ==> fminsearch at 205
fv(:,1) = funfcn(x,varargin{:});
Error in ==> Q5 at 99
sig4=fminsearch(@P5Function ,1.5);% minimse the cost function using
'fminsearch' giving a predicted value for sigma4
Matt Tearle
Matt Tearle 2011 年 3 月 2 日
Actually, you *can* use a string... but you *should* use a function handle.

Matt Tearle
Matt Tearle 2011 年 3 月 2 日
What are your globals c2 and z? Not having access to them, I hard-coded in a scalar for c2 and a 201-element vector for z, and it worked fine for me.
While we're here, don't use globals. Do this instead:
function J=P5F(Sig,c2,z)
[etc]
Then, in p5final
c2 = <something>;
z = <something>;
f = @(sig) P5F(sig,c2,z)
sig4=fminsearch(f,1.5)

この質問は閉じられています。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by