Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Combining separate files

1 visualización (últimos 30 días)
buxZED
buxZED el 2 de Mzo. de 2011
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
??? 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

Respuestas (2)

Walter Roberson
Walter Roberson el 2 de Mzo. de 2011
The argument to fminsearch must be a function handle, not a string. Use @P5F instead of 'P5F'
  2 comentarios
buxZED
buxZED el 2 de Mzo. de 2011
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 el 2 de Mzo. de 2011
Actually, you *can* use a string... but you *should* use a function handle.

Matt Tearle
Matt Tearle el 2 de Mzo. de 2011
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)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by