error: Function definition is misplaced or improperly nested error?
12 次查看(过去 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;
...
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 MATLAB Report Generator 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!