Is there any way to use a function defined in the workspace inside a function defined in a .m file?
조회 수: 1 (최근 30일)
이전 댓글 표시
I trying of use fmincon and for that I have to create a function with de nonlinear constrains, but when creating the function that contains the nonlinear constraints should I use some functions defined in the workspace, but apparently did not exist within the function workspace (.m file).
I have:
function [ci,ce] = nonlinears(z)
ci=cineq(z(1),z(2),z(3),z(4));
ce=ceq(z(1),z(2),z(3),z(4));
end
where cineq and ceq are functions defined in the workspace.
I wonder if there is any way to use the functions defined within the worskpace in the function worskpace.
Please help! and thanks in advance!
댓글 수: 0
채택된 답변
Jan
2014년 11월 16일
The "workspace" is the set of locally used variables. To be exact, you cannot "define a function in a workspace". Do you mean, that the functions cineq and ceq are defined inside an M-file?
댓글 수: 5
Matt J
2014년 11월 17일
Well, then why not nest all the functions that share variables inside the common parent function where those shared variables are created.
추가 답변 (1개)
Matt J
2014년 11월 16일
편집: Matt J
2014년 11월 16일
Make sure you are aware of and understand the differences between Local Functions, Nested Functions, and Anonymous Functions
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!