Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

class

Determine class of object

Syntax

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)

Description

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

    Note:   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.

Examples

Return the class of Java® object obj:

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

Return class of any MATLAB variable:

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

Related Examples

See Also

| |

Introduced before R2006a

Was this topic helpful?