MATLAB Object-Oriented Programming

(Joyce) #1
function o = times(obj,val)
u8 = uint8(obj).*val;
o = DocUint8(u8);
end

When you override a uint8 method, MATLAB calls the subclass method, not the base
class method. The subclass method must:


  • Call the uint8 times method on the DocUint8 object data.

  • Construct a new DocUint8 object using the uint8 data.


After adding the times method to the DocUint8 class, the output of multiplication
expressions is an object of the DocUint8 class:

showImage(img1.*1.8);

12 How to Build on Other Classes

Free download pdf