MATLAB Object-Oriented Programming

(Joyce) #1
end

methods
function obj = MuxCard(inptnames, inptrates, outpname)
obj = obj@int32(inptrates);
obj.InPutNames = inptnames;
obj.OutPutName = outpname;
end

function x = get.OutPutRate(obj)
x = sum(obj);
end

function x = subsref(card, s)
if strcmp(s(1).type,'.')
base = subsref@int32(card, s(1));
if isscalar(s)
x = base;
else
x = subsref(base, s(2:end));
end
else
x = subsref(int32(card), s);
end
end
end
end

Construct MuxCard Object


The constructor takes three arguments:


  • inptnames — Cell array of input port names

  • inptrates — Vector of input port rates

  • outpname — Name for the output port


omx = MuxCard({'inp1','inp2','inp3','inp4'},[3 12 12 48],'outp')

omx =

1x4 MuxCard array with properties:

InPutNames: {'inp1' 'inp2' 'inp3' 'inp4'}

12 How to Build on Other Classes

Free download pdf