Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Combining separate files
2 ビュー (過去 30 日間)
古いコメントを表示
??? 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
0 件のコメント
回答 (2 件)
Walter Roberson
2011 年 3 月 2 日
The argument to fminsearch must be a function handle, not a string. Use @P5F instead of 'P5F'
2 件のコメント
Matt Tearle
2011 年 3 月 2 日
Actually, you *can* use a string... but you *should* use a function handle.
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)
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!