error: Function definition is misplaced or improperly nested error?
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Abdelrahman Taha
el 31 de En. de 2020
Editada: Abdelrahman Taha
el 31 de En. de 2020
I am defining a nested function (bicomp1) inside a function (biaxialcomp) whose output is to be minimised using the fmincon optimization function, but I get an error that this function is misplaced or improperly nested. What could be the problem with it?
function [Mux, Muy] = biaxialcomp(c,app,gc,gs,bar,n,i)
th = [10 20 30 40 50 60 70 80];
Mux = zeros(1,8);
Muy = zeros(1,8);
for iv = 1:8
% first potential scenario
if app.b*tand(th(iv)) < app.t
tt = app.b*sind(th(iv))+app.t*cosd(th(iv));
c_opt = fmincon(@bicomp1,c,[],[],[],[],0,tt);
function obj = bicomp1(c)
a = 0.8*c;
Xna = a/sind(th(iv));
fcu = 0.67*app.Fcu/gc;
...
0 comentarios
Respuesta aceptada
Stephen23
el 31 de En. de 2020
Editada: Stephen23
el 31 de En. de 2020
"What could be the problem with it?"
This:
if ...
...
function obj = bicomp1(c)
Function definitions cannot be nested inside control statements. To get the effect you are looking for, you will have to parameterize your function (i.e. either use a nested function or an anonymous function with the required parameters):
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Report Generator 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!