0

I'm trying to add a method to the containers.Map class, for example

function sayHello(obj)
    disp('Hello!')
end

And I want to be able to do:

map = containers.Map('Foo', 'Bar');
map.sayHello

I've added sayHello.m to /my/path/+containers/@Map, but methods containers.Map and which -all sayHello both don't find my method.

What am I doing wrong? Is it not possible to add methods to this class?

Thanks

rwb
  • 4,309
  • 8
  • 36
  • 59
  • 1
    It may not be possible to add methods to a built-in class, but you should be able to subclass it. – Jonas Apr 04 '16 at 14:54
  • Thanks @Jonas, but I have managed to add methods (in the way described in my question) to `cell`, `char` and `fints` - just not `containers.Map`. – rwb Apr 04 '16 at 15:03
  • 1
    Because `containers.Map` is relatively new (R2008b compared to the other classes you listed), it probably falls under different method overloading rules as [discussed here](http://stackoverflow.com/questions/34602298/add-a-method-to-matlab-table-class/34603252#34603252) and needs to be sub-classed for extension. – TroyHaskin Apr 04 '16 at 17:33

1 Answers1

0

As pointed out in the comments, this looks to not be possible. Rubbish.

See also here.

Community
  • 1
  • 1
rwb
  • 4,309
  • 8
  • 36
  • 59