Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
MATLAB
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Classes and object-oriented programming === MATLAB supports [[object-oriented programming]] including classes, [[inheritance (object-oriented programming)|inheritance]], virtual dispatch, packages, [[pass-by-value]] semantics, and [[pass-by-reference]] semantics.<ref>{{cite web|url=http://www.mathworks.com/help/matlab/object-oriented-programming.html |title=Object-Oriented Programming|publisher=MathWorks|access-date=August 14, 2013}}</ref> However, the syntax and calling conventions are significantly different from other languages. MATLAB has value classes and reference classes, depending on whether the class has ''handle'' as a super-class (for reference classes) or not (for value classes).<ref>{{cite web|title=Comparing Handle and Value Classes|url=http://www.mathworks.com/help/matlab/matlab_oop/comparing-handle-and-value-classes.html|publisher=MathWorks}}</ref> Method call behavior is different between value and reference classes. For example, a call to a method: <syntaxhighlight lang="matlab"> object.method(); </syntaxhighlight> can alter any member of ''object'' only if ''object'' is an instance of a reference class, otherwise value class methods must return a new instance if it needs to modify the object. An example of a simple class is provided below: <syntaxhighlight lang="matlab"> classdef Hello methods function greet(obj) disp('Hello!') end end end </syntaxhighlight> When put into a file named <code>hello.m</code>, this can be executed with the following commands: <syntaxhighlight lang="matlabsession"> >> x = Hello(); >> x.greet(); Hello! </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)