error: Function definition is misplaced or improperly nested error?
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Abdelrahman Taha
il 31 Gen 2020
Modificato: Abdelrahman Taha
il 31 Gen 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 Commenti
Risposta accettata
Stephen23
il 31 Gen 2020
Modificato: Stephen23
il 31 Gen 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):
Più risposte (0)
Vedere anche
Categorie
Scopri di più su MATLAB Report Generator in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!