class
Return a variable class name or create an old-style named object.
📝Syntax
name = class(var)
obj = class(st, className)
📥Input Arguments
Parameter Description
var a variable
st a structure
className a class name as a string
📤Output Arguments
Parameter Description
name a string
obj an old-style object of type className based on structure st
📄Description

class(var) returns the class name of var.

For sparse arrays, class returns the stored value class, such as double or logical. Use issparse to test sparse storage.

For classdef value and handle objects, class returns the classdef class name, including package qualification when applicable.

class(st, className) preserves Nelson old-style object creation and is independent from classdef class definitions.

💡Examples
Return a built-in class name.
A = 3;
name = class(A)
Return the stored value class of a sparse array.
S = sparse([2 0 3]);
name = class(S)
tf = issparse(S)
Return classdef value and handle class names.
clear classes
d = [tempdir(), 'nelson_help_class/'];
mkdir(d);
filewrite([d, '/NelsonHelpClassPoint.m'], ["classdef NelsonHelpClassPoint"; "  properties"; "    X = 0"; "  end"; "end"]);
filewrite([d, '/NelsonHelpClassCounter.m'], ["classdef NelsonHelpClassCounter < handle"; "  properties"; "    Count = 0"; "  end"; "end"]);
addpath(d);
p = NelsonHelpClassPoint();
h = NelsonHelpClassCounter();
pointClass = class(p)
handleClass = class(h)
delete(h)
🔗See Also
isaissparseisobjectclassdef
🕔Version History
Version Description
1.0.0 initial version
2.0.0 classdef value and handle object behavior documented
2.0.0 sparse arrays report their stored value class
Edit this page on GitHub