필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Combining separate files

조회 수: 1 (최근 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