Академический Документы
Профессиональный Документы
Культура Документы
code sample:
function[c] = add(a,b)
c=a+b;
end
To execute the exercise, you need to call the exercise.m file from matlab/octave
commandline.
Function Handle:
A function handle is a MATLAB data type that stores an association to a function.
Syntax:
f = @function_name
example:
function y = computeSquare(x)
y = x.^2;
end
b = f(a)
If the function does not require any inputs, then you can call the function with
empty parentheses, such as
h = @ones;
a = h()
Without the parentheses, the assignment creates another function handle.
a=h
Thus:
a is now @ones
Function handles are variables that you can pass to other functions.
Eg:
q = integral(f,0,1);
Anonymous function:
Syntax:
h = @(arglist)anonymous_function
eg:
sqr = @(n) n.^2;
x = sqr(3)
Referencing Package Members from Outside the Package:
Functions, classes, and other packages contained in a package are scoped to that
package. To reference any of the package members, prefix the package name to the
member name, separated by a dot. For example, the following statement creates an
instance of MyClass, which is contained in mypack package.
obj = mypack.MyClass;
Accessing Class Members Various Scenarios:
This section shows you how to access various package members from outside a
package. Suppose that you have a package mypack with the following contents:
+mypack
+mypack/myfcn.m
+mypack/@MyFirstClass
+mypack/@MyFirstClass/myFcn.m
+mypack/@mMyFirstClass/otherFcn.m
+mypack/@MyFirstClass/MyFirstClass.m
+mypack/@MySecondClass
+mypack/@MySecondClass/MySecondClass.m
+mypack/+mysubpack
+mypack/+mysubpack/myFcn.m
Invoke the myFcn function in mypack:
mypack.myFcn(arg)
Matlab Code
Abstract class or
interface in matlab
Constant class
variables
properties (Constant)
PRESSURE_NC_PA =
101352.9322071000;
end
properties
%> String used to
identify the type of PLSeg.
type = 'pipe';
Changing instance
variables
end
If no access is specified, the
default access specifier is
public.
properties (SetAccess =
private, GetAccess = public)
densityCorrectingFactor =
1;
end
Abstract methods
methods (Abstract)
[mySigmaNM,
mySigmaStdNM, errorId,
errorString] =
computesigma(MyPhasePro
perties, pressurePa,
temperatureK)
end
int
densityCorrectingFactor
= 1;
private void
setDensityCorrectingFact
or(int
densityCorrectingFactor)
{
this.densityCorrectingFac
tor =
densityCorrectingFactor;
}
Public void
getDensityCorrectingFact
or() {
return
this.densityCorrectingFac
tor;
}
public abstract
Map<String, Object>
computesigma(PhaseProp
erties MyPhaseProperties,
double pressurePa,
double temperatureK);
and the returned map will
have the required output
values in matlab i.e
mySigmaNM, mySigmaStdNM,
errorId, errorString
Constructor
Methods / Functions
Multiple inheritance
function MyPhaseProperties
= PhaseProperties()
% Do nothing
end
% Commented code
%{ This
Is
Block
Comment
}%
PhaseProperties() {
// Do nothing
}
// Commented code
/* This
Is
Block
Comment
*/
logical
boolean
byte
short
int
long
float
double
double
double
float
long
int
short
byte
boolean
single
float
double
String
char
String
char[]
char(m-by-n, m,n>1)
String[]
uint8
int8
byte
short
int
long
float
double
uint16
int16
short
int
long
float
double
uint32
int32
int
long
float
double
uint64
int64
long
float
double
String[]
Java object
Object
Object[]
MATLAB object
Unsupported
Java Object
logical
Boolean
double
Double
single
Float
Character
String
uint8
int8
Byte
MATLAB Argument
Java Object
uint16
int16
Short
uint32
int32
Integer
uint64
int64
Long
String[]
Java object
Object
Object[]
MATLAB object
Unsupported