Overload basic arithmetic for classes arrays?

1 Ansicht (letzte 30 Tage)
Alex Kashuba
Alex Kashuba am 24 Mär. 2020
I have a an object obj with several fields, say
obj.a = [1 -1];
obj.b = [0 1; 0 0];
and can override a plus operator
obj = obj1 + obj2
as
obj.a = obj1.a + obj2.a
obj.b = obj1.b + obj2.b
The QUESTION 1: What if I have a class arrays, say obj1(1,2) and obj1(2,1) and want to sum them in the same way as it is performed for double i.e. getting obj(2,2)? Of course I need it for the arbitrary sizes and dimensions. Function arrayfun() is no help, since it does not do implicit expansion. The bsxfun() would do the job, but it is defined for double, int, char, etc.
The QUESTION 2: Same question for mtimes: how can i do matrix multiplication if times function is defined?

Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by