Overload basic arithmetic for classes arrays?
4 ビュー (過去 30 日間)
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
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?