How do you use ./ operator on array of custom class
Show older comments
Hi,
I've written a custom class with overloads for mathematical operators. I now have arrays a and b and I want to do element-wise division.
My first guess was that the ./ operator would map the / operator over the elements of the array, however with mrdivide defined I get the error "Undefined operator './' for input arguments of type".
When I add the following code to my class
function r = rdivide(a, b)
for i = 1:length(a)
r(i) = a / b
end
end
I get the error "Error using / Too many input arguments" with line numbers pointing into my mrdivide function. My mrdivide function seems to work when I use it on its own.
Is this the correct way to implement element-wise division?
Thanks.
3 Comments
darova
on 18 Feb 2020
Did you try

Rik
on 18 Feb 2020
@Darova that looks like an answer to me. When moving it to the answer section, could you make it code instead of an image?
I also have a suggestion for the code itself: use numel instead of length. That way this overload will also work for non-vector shaped arrays.
Jefferson Carpenter
on 18 Feb 2020
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!