Functions
When creating a MATLAB function, the name of the file should match the name of the first function in the file. Valid function names begin with an alphabetic character, and can contain letters, numbers, or underscores. Functions are also often case sensitive.Function handles
MATLAB supports elements of lambda calculus by introducing function handles,[18] or function references, which are implemented either in .m files or anonymous[19]/nested functions.[20]Classes and object-oriented programming
MATLAB supports object-oriented programming including classes, inheritance, virtual dispatch, packages, pass-by-value semantics, and pass-by-reference semantics.[21] 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).[22]Method call behavior is different between value and reference classes. For example, a call to a method
object.method();
An example of a simple class is provided below.
classdef hello
methods
function greet(this)
disp('Hello!')
end
end
end
>> x = hello;
>> x.greet();
Hello!
No comments:
Post a Comment