error: Function definition is misplaced or improperly nested error?

18 次查看(过去 30 天)
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;
...

采纳的回答

Stephen23
Stephen23 2020-1-31
编辑:Stephen23 2020-1-31
"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):

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Report Generator 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by