Dynamically increasing propery size in object
Mostrar comentarios más antiguos
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 comentarios
Jan
el 10 de Oct. de 2021
What does "large" mean and why is a pre-allocation not possible?
TAB
el 10 de Oct. de 2021
Walter Roberson
el 10 de Oct. de 2021
What assurance do you have that you will not fill up your memory?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Function Creation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!