oop - Mathematical operations in heterogeneous arrays (Matlab) -


i created heterogeneous object array in matlab derived matlab.mixin.heterogeneous class. array contains objects of superclass cells , subclasses neuron, astrocyte etc. methods want assign subclasses supposed simulate behavior depending on different stimuli. in order calculate behavior, need objects perform mathematical operations. when define function uses operators in methods of class, matlab tells me e.g.:

undefined operator '-' input arguments of type 'cells'.

then tried construct superclass multiple inheritances ( cells < matlab.mixin.heterogeneous & double ), error appears:

error using cells: class 'cells' cannot subclass of matlab.mixin.heterogeneous , inherit 'subsasgn' method class 'double'.

which not surprising, says in description of 'matlab.mixin.heterogeneous'

you cannot override following methods in subclasses:

...

subsasgn

as other idea define methods functions outside classes, wanted ask if there possibility perform mathematical operations in heterogeneous object arrays.

you need define arithmetic operators methods of classes otherwise not able operate on custom class. example, support subtraction, need overload minus class

methods     function self = minus(self, other)         % loop through array , apply - operator each          k = 1:numel(self)             self(k).prop1 = self(k).prop1 - other.prop1;             self(k).prop2 = self(k).prop2 - other.prop2;         end     end end 

note minus method hetergeneous array needs ensure elements of self of different classes handled appropriately.

a list of arithmetic operator methods can found here


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -