class — Return the MATLAB class name for scalars, arrays, handles, and objects.
class(x) returns the name of the MATLAB class that x belongs to. The result is a string scalar that you can use for diagnostics, branching, or display logic.
How class works in RunMat
- Real or complex double-precision inputs (including empty numeric arrays) report
"double". Integer scalars or tensors report their narrow class such as"int16"or"uint8". - Logical scalars and arrays report
"logical". Character arrays return"char", while string scalars or arrays return"string". - Cell arrays, structs, and user-defined
classdefobjects report"cell","struct", or the class name that defined the object. - Function handles and anonymous closures both report
"function_handle". Listeners return"event.listener". gpuArrayvalues report"gpuArray"without gathering data. UseclassUnderlyingif you need the element type of the device array.- Handle objects, including deleted handles, return the class name that introduced the handle. Metadata-only values such as
classref("Point")report"meta.class".
How class runs on the GPU
class is an introspection-only builtin. When the input resides on the GPU, RunMat reads the residency metadata, returns the class name immediately, and leaves the data in place. No kernels are launched and no buffers are copied back to the CPU, so providers do not need to expose any hooks.
GPU memory and residency
You do not need to call gpuArray purely to query a value’s class. The auto-offload planner keeps tensors on the GPU whenever profitable, and class simply returns the residency-aware class name without altering where the data lives. Explicit gpuArray and gather calls remain available for compatibility with MATLAB code that manages residency manually.
Examples
Check the class of a numeric scalar
c = class(42)Expected output:
c = "double"Inspect the class of a string array
names = ["Ada", "Grace", "Edsger"];
class_name = class(names)Expected output:
class_name = "string"Determine whether a cell array stays typed as a cell
cells = {1, "two", 3};
cell_class = class(cells)Expected output:
cell_class = "cell"Detect the class of gpuArray data without gathering
G = gpuArray(rand(4));
g_class = class(G)Expected output:
g_class = "gpuArray"Report the class name of a custom object
P = classref("Point").origin();
point_class = class(P)Expected output:
point_class = "Point"FAQ
Does class return a string or a character array?
class returns a string scalar, matching modern MATLAB behaviour. Convert the result with char(class(...)) if you need a legacy character row vector.
How do I check whether a value is numeric?
Use isa(x, "numeric") to handle floats, complex numbers, and integers. class reports the concrete class ("double", "int32", and so on).
Will class gather gpuArray inputs?
No. RunMat inspects metadata and returns "gpuArray" immediately; buffers stay on the device.
What does class return for handle objects?
class returns the object’s defining class name (for example "MyHandleClass"). Use isa(h, "handle") to test for handle semantics.
What happens if I pass a struct or cell array?
Structs return "struct" and cell arrays return "cell", matching MATLAB.
What is the class of function handles?
Both named function handles and anonymous closures report "function_handle".
Can I distinguish string and char arrays?
Yes. class("hello") yields "string" while class('hello') yields "char".
What about metadata objects such as classref?
Calling class(classref("Point")) returns "meta.class". Use the returned meta-class object to inspect properties or superclasses.
Related functions to explore
These functions work well alongside class. Each page has runnable examples you can try in the browser.
isa, isnumeric, gpuArray, gather, ischar, isstring, which, who, whos
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how class works, line by line, in Rust.
- View class.rs on GitHub
- Learn how the runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.