function in a script file
조회 수: 2 (최근 30일)
이전 댓글 표시
Can I write a function inside a if statement in a script file?
댓글 수: 1
Walter Roberson
2022년 9월 2일
@PA if you are not able to understand the responses, then please ask for clarification... after restoring the code, so that people will understand the situation you are working with.
채택된 답변
Walter Roberson
2022년 9월 1일
"function" statements can never be inside a flow control statement.
Anonymous functions can be defined inside flow control.
댓글 수: 0
추가 답변 (2개)
David Hill
2022년 9월 1일
a=5;b=10;
if b>a
c=executeFunction(a,b)
end
function c=executeFunction(a,b)
c=b*3+a;
end
댓글 수: 3
Steven Lord
2022년 9월 1일
If obj is an instance of a class with a method named CON_Pattern you could call the method as obj.CON_Pattern or as CON_Pattern(obj). But you would have to define it as function CON_Pattern(obj).
Steven Lord
2022년 9월 1일
You cannot define a function inside an if statement.
You can define a function in a script or function file outside of the if statement and call it inside.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!