This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Determine class of object


ClassName = class(object)
obj = class(s,'class_name')
obj = class(s,'class_name',parent1,parent2,...)
obj = class(struct([]),'class_name',parent1,parent2,...)
obj_struct = class(struct_array,'class_name',parent_array)


ClassName = class(object) returns a character vector specifying the class of object. See Fundamental MATLAB Classes for more information on MATLAB® classes.


Before MATLAB 7.6 (classes defined without a classdef statement), class constructors called the class function to create the object. The following class function syntaxes apply only within classes defined before Version 7.6.

obj = class(s,'class_name') creates an array of class class_name objects using the struct s as a pattern to determine the size of obj.

obj = class(s,'class_name',parent1,parent2,...) inherits the methods and fields of the parent objects parent1, parent2, and so on. The size of the parent objects must match the size of s or be a scalar (1-by-1), in which case MATLAB performs scalar expansion.

obj = class(struct([]),'class_name',parent1,parent2,...) constructs an object containing only fields that it inherits from the parent objects. All parents must have the same, nonzero size, which determines the size of the returned object obj.

obj_struct = class(struct_array,'class_name',parent_array) maps every element of the parent_array to a corresponding element in the struct_array to produce the output array of objects, obj_struct.

All arrays must be of the same size. If either the struct_array or the parent_array is of size 1-by-1, then MATLAB performs scalar expansion to match the array sizes.

To create an object array of size 0-by-0, set the size of the struct_array and parent_array to 0-by-0.


Return the class of Java® object obj:

import java.lang.*;
obj = String('mystring');

Return class of any MATLAB variable:

h = @sin;

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a