| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
Methods define all aspects of an object's behavior. Consequently, most classes implement many methods that an object user is unlikely to call directly. The user documentation for the object you are using describes the operations you can perform on any particular object.
You can list the methods defined by a class with the methods or methodsview functions:
methods('timeseries')
Methods for class timeseries:
addevent gettsbetweenevents set
addsample horzcat setabstime
createTstoolNode idealfilter setinterpmethod
ctranspose init setprop
...
gettsatevent pvset var
gettsbeforeatevent rdivide vertcat
gettsbeforeevent resample
Static methods:
tsChkTime tsgetrelativetime You call an object's method using dot notation:
returnedValue = object.MethodName(args,...)
You also can call a method using function syntax, passing the object as the first (left-most) argument.
For example, MException objects have a getReport method that returns information about the error.
try surf catch me disp(me.getReport) end Error using ==> surf at 50 Not enough input arguments.
Dot and function notation are usually equivalent. That is, both of the following statements return the MException report:
rpt = getReport(me); % Call getReport using function notation rpt = me.getReport; % Call getReport using dot notation
It is possible for the function syntax to call an unexpected method if there is more than one object in the argument list. Suppose there are two classes, ClassA and ClassB, that define a method called addData. Suppose further that ClassA is defined as being inferior to ClassB in precedence (something that the class designer can do in the class definition). In this situation, given objA is of ClassA and objB is of ClassB, the following two statement call different methods:
addData(objA,objB) % Calls objB.addData objA.addData(objB) % Calls objA.addData
If ClassA and ClassB had equal precedence, then the left-most argument determines which method MATLAB calls (i.e., objA.addData in both statements).
It is unlikely that you will encounter this particular scenario, however, if you are calling a method that accepts more than one object as arguments, using dot notation removes any ambiguity about which object's method MATLAB calls.
While methods sometimes return objects of the same class, this is not always the case. For example, the MException object's getReport returns a character string:
try surf catch me rpt = me.getReport; end whos Name Size Bytes Class Attributes me 1x1 780 MException rpt 1x171 342 char
Methods can return any type of value and properties can contain any type of value. However, class constructor methods always return an object or array of objects of the same type as the class.
![]() | Accessing Object Data | Desktop Tools Are Object Aware | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |