Dynamically increasing propery size in object
古いコメントを表示
Hello Everyone,
I know dynamically increasing array size (without pre-allocation) is not good for performnace and there are several discussion around it in this forum. But is this also true for property inside handle class ?
I am trying to write a class where I can dynamically increase the size of a propery. A simplified example below
classdef MySignal < handle
properties (Access = public)
Name = ''
Source = 'DAQ11'
end
methods
function obj = MySignal(name)
obj.Name = name;
end
end
end
Another class will use MySignal class
classdef DataCollection < handle
properties
AquiredBy = ''
Sig = MySignal.empty; % Create empty array of MySignal
end
methods % Constructor
function obj = DataCollection(user_name)
AquiredBy = user_name;
end
end
methods
function AddSignal(obj, name) % Function to add signal in list on demand
obj.Sig = [obj.Sig MySignal(name)];
end
end
end
DataCollection class will be used to add signals later
data = DataCollection('user_1');
data.AddSignal('Signal_1');
%....
%.... signal search, validation, comparision etc.
data.AddSignal('Signal_2');
%....
%....
Number of signals are large and pre-allocation is not possible.
Is this good approach or any better option available ?
(Using Matlab R2019b)
Thanks
3 件のコメント
Jan
2021 年 10 月 10 日
What does "large" mean and why is a pre-allocation not possible?
TAB
2021 年 10 月 10 日
Walter Roberson
2021 年 10 月 10 日
What assurance do you have that you will not fill up your memory?
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!