function in a script file

3 次查看(过去 30 天)
Can I write a function inside a if statement in a script file?
  1 个评论
Walter Roberson
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
Walter Roberson 2022-9-1
"function" statements can never be inside a flow control statement.
Anonymous functions can be defined inside flow control.

更多回答(2 个)

David Hill
David Hill 2022-9-1
a=5;b=10;
if b>a
c=executeFunction(a,b)
end
c = 35
function c=executeFunction(a,b)
c=b*3+a;
end
  3 个评论
PA
PA 2022-9-1
yeah its written for class method
Steven Lord
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
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.

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by