Role of Classes in MATLAB
In this section...
“Classes” on page 3-2
“Some Basic Relationships” on page 3-4Classes
In the MATLAB language, every value is assigned to a class. For example, creating a
variable with an assignment statement constructs a variable of the appropriate class:a = 7;
b = 'some text';
s.Name = 'Nancy';
s.Age = 64;
whoswhos
Name Size Bytes Class Attributesa 1x1 8 double
b 1x9 18 char
s 1x1 370 structBasic commands like whos display the class of each value in the workspace. This
information helps MATLAB users recognize that some values are characters and display
as text while other values are double precision numbers, and so on. Some variables can
contain different classes of values like structures.Predefined ClassesMATLAB defines fundamental classes that comprise the basic types used by the language.
These classes include numeric, logical, char, cell, struct, and function handle.User-Defined ClassesYou can create your own MATLAB classes. For example, you could define a class to
represent polynomials. This class could define the operations typically associated with
MATLAB classes, like addition, subtraction, indexing, displaying in the command window,
and so on. These operations would need to perform the equivalent of polynomial addition,
polynomial subtraction, and so on. For example, when you add two polynomial objects:3 MATLAB Classes Overview