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!