How to return to the main function from function file by using return
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm using simulated annealing to do minimization for my model.
The following is my main function.
lb=[0.01 0.01 0.01]; ub=[0.9 3.0 0.9]; z=[0.3 2 0.4];
for i=1:100
h=@test;
est=simulannealbnd(h,z,lb,ub,options);
end
for the h function file as shown,
i have one condition to consider to estimate z
let's say the condition=exp(z(2)+(1-z(1)))-(1/z(3));
if the condition is fulfill
then run
sumQ=0;
for i=2:length(Y)
Q=model likelihood
sumQ=sumQ+Q;
end
Qfun=sumQ;
else
return;
end
Otherwise, have to go back to the main function to load simulannealbnd to obtain the new set of z from lb and ub.
The question is: When i use return to go back to main function, the error showing Qfun is not assigned any value?
Anyone can help with return command to go back to the main function and run again?
0 comentarios
Respuestas (2)
the cyclist
el 20 de Ag. de 2013
You could put the line
Qfun = [];
before your return statement.
5 comentarios
Walter Roberson
el 20 de Ag. de 2013
Put
Qfun = sumQ
right before the return
3 comentarios
Image Analyst
el 21 de Ag. de 2013
Just put that line immediately after the function line, before any of the other lines in the function. Then Qfun is guaranteed to have a value, even if it's null, no matter what else happens in the code (i.e. you encounter an error before you get to assign it with the desired values). So that error about exiting the function without assigning QFun will never happen - though you may get other errors.
Ver también
Categorías
Más información sobre Image Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!