0

What are the differences between these two calling sequences get(a) and a.get()?

load gong
a = audioplayer(y, Fs);
a.get
get(a)
rinkert
  • 6,593
  • 2
  • 12
  • 31
sci9
  • 700
  • 1
  • 7
  • 21
  • 5
    Nothing, take a look [here](https://nl.mathworks.com/help/matlab/matlab_oop/create-a-simple-class.html), section 'Call Methods'. – rinkert Aug 24 '19 at 14:31

1 Answers1

1

There is no difference by default. However, the behavior can be modified.

By default, for an object of a custom class, obj.method(arg1,arg2,...) is syntactic sugar for method(obj,arg1,arg2,...). This means that when you write the former, MATLAB pretends you wrote the latter and proceeds accordingly.

However, it is possible to overload the method subsref for the class, in which case this function will be called for the syntax obj.method(arg1,arg2,...). That is, MATLAB interprets it as an indexing operation (.method) followed by another indexing operation ((arg1,arg2,...)). The subsref method is called to evaluate these indexing operations. It is possible to implement it such that the appropriate method is called in this case, but custom indexing code is executed for other indexing operations such as obj(x) or obj{x}. See for example here.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120