Main Content

class

Class of object

Description

example

className = class(obj) returns the name of the class of obj.

Examples

collapse all

Get the class name of a Java® object.

jObject = java.lang.String('Java string');
className = class(jObject);
disp(className)
java.lang.String

Determine the class of a variable.

h = @sin;
className = class(h);
disp(className)
function_handle

Input Arguments

collapse all

Object or literal, specified as a variable or an expression.

Example: class(date)

Output Arguments

collapse all

Name of the class, returned as a character vector.

More About

collapse all

Obsolete Class Definition Syntax

In class definition 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,ClassName) creates an array of objects of the specified class using the struct s as a pattern to determine the size of obj.

obj = class(s,ClassName,parent1,parent2,...) inherits the methods and fields of the specified parent objects. The size of the parent objects must match the size of s or be a scalar (1-by-1). If they are scalar, MATLAB performs scalar expansion.

obj = class(struct([]),ClassName,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.

objStruct = class(structArray,ClassName,parentArray) maps every element of the parentArray to a corresponding element in the structArray to produce the output array of objects, objStruct.

All arrays must be of the same size. If either the structArray or the parentArray 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 structArray and parentArray to 0-by-0.

Extended Capabilities

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

Version History

Introduced before R2006a