How to declare a function as Static if it is defined as an individual file under the class folder?
8 ビュー (過去 30 日間)
古いコメントを表示
In the class definition file we define Static functions as such:
methods(Static)
function SomeFunction()
end
end
However, what if the function is defined as an individual file under the class folder? Can I make some declarations like a .h file in C++ or something like:
methods(Static)
SomeFunction(); %This function is actually defined in the class folder
end
0 件のコメント
回答 (1 件)
Dave B
2021 年 8 月 6 日
You can do exactly what you're describing. The trick (if there is one) is that you leave the keyword function out in the classdef file. Here's an example
Create a folder @foo
Inside @foo, create a foo.m:
classdef foo
methods (Static)
argout = staticmethod1(argin)
staticmethod2(argin)
end
end
And a staticmethod1.m:
function argout = staticmethod1(argin)
argout = argin^2;
end
And a staticmethod2.m:
function staticmethod2(argin)
disp("argin=" + argin)
end
Test:
>> foo.staticmethod1(3)
ans =
9
>> foo.staticmethod2("asdf")
argin=asdf
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で MATLAB Compiler についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!