Write class methods outside the class file

31 ビュー (過去 30 日間)
Nycholas Maia
Nycholas Maia 2019 年 9 月 16 日
コメント済み: Nycholas Maia 2019 年 9 月 16 日
I have a very large MATLAB class with a lot of methods and I would like to organize them to facilitate the source code maintenance.
So I was thinking to put each Class method in your own MATLAB file, like a pure function and then call the function inside the Class method like this:
classdef my_class < handle
properties
big_data
end
methods
function [] = my_method1(obj, param1)
% Here I call the pure function:
my_function1(obj.big_data, param1)
end
function [] = my_method2(obj, param1, param2)
% Here I call the pure function:
my_function2(obj.big_data, param1, param2)
end
end
So I will have 2 other files:
  • my_function1.m
  • my_function2.m
My question is:
Doing in that way, when I call the pure function MATLAB will pass the obj.big_data by reference or by value?
Inside these pure functions I'm not modifying the big_data property. This is read-only property.

採用された回答

Steven Lord
Steven Lord 2019 年 9 月 16 日
Rather than defining the class methods in the classdef file to call a separate function, I'd just define them in a separate file in a class folder as shown on this documentation page.
Note that there are some methods that must be defined in the classdef file itself as stated in the last section on that page. The most common and important of those is the class constructor.
This other documentation page may also be of interest to you.
  1 件のコメント
Nycholas Maia
Nycholas Maia 2019 年 9 月 16 日
thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSoftware Development Tools についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by