isequal — Test array equality in MATLAB and RunMat.
isequal(A, B, ...) returns one host logical scalar when all inputs match in shape and values. Numeric, logical and character values compare across classes with exact integer comparisons; strings compare as text. NaNs compare unequal, including recursively.
Syntax
tf = isequal(A, B, ...)Inputs
A- Type
Any- Required
- Yes
- Description
- First value.
B- Type
Any- Required
- Yes
- Description
- Second value.
others- Type
Any- Required
- Variadic
- Description
- Additional values compared against A.
Returns
tf- Type
LogicalArray- Description
- Host logical scalar; numeric values compare across classes without lossy conversion.
Errors
RunMat:isequal:NotEnoughInputs- When
- Fewer than two inputs are supplied.
- Message
isequal: requires at least two input arguments
RunMat:isequal:Internal- When
- Resident input ownership, payload validation, or download fails.
- Message
isequal: internal error
RunMat:isequal:TooManyOutputs- When
- More than one output is requested.
- Message
isequal: too many output arguments
Behavior
isequal(A, B) compares two values for equality.
isequal(A, B, C, ...) compares all inputs against each other; returns true only if all are equal.
Arrays must have identical shape (size) to be equal.
Numeric values compare across classes without lossy promotion of wide integers.
All corresponding elements must be identical for arrays to be equal.
NaN values are NOT equal to each other (NaN ~= NaN).
Empty arrays [] are equal to other empty arrays with the same shape.
Cell arrays are compared element-by-element recursively.
Structs are compared field-by-field.
Sparse values compare to full values, and real values compare to complex values when the imaginary component is zero.
Structs and struct arrays compare matching field names and values regardless of field insertion order.
Complex scalars and one-element complex arrays compare component values exactly across storage classes.
Nested cells, structs and struct arrays are compared recursively; unsupported object, callable, symbolic, foreign and other value kinds return false without invoking user code.
Zero requested outputs evaluates and discards the result; more than one output fails before any provider access. At least two inputs are required.
Placement and execution
All resident numeric leaves, including leaves in cells and structs, download through their exact owning provider with class, shape and payload validation. Inputs retain residency; the result is a host logical scalar. There is no device comparison or fusion kernel.
Distributed arguments require materialization before recursive comparison. The portable async runtime binding is shared by interpreter and compiled calls; downloads may suspend or fail. No callbacks, workspace, filesystem, randomness or time services are used. Transfer costs and scheduling belong to shared materialization services.
Examples
Compare structures independently of field order
left = struct('a', 1, 'b', 2);
right = struct('b', 2, 'a', 1);
tf = isequal(left, right)Expected output:
tf = trueComparing two identical scalars
tf = isequal(5, 5)Expected output:
ans = logical
1Comparing two different scalars
tf = isequal(5, 6)Expected output:
ans = logical
0Comparing identical matrices
A = [1 2; 3 4];
B = [1 2; 3 4];
tf = isequal(A, B)Expected output:
ans = logical
1Comparing matrices with different shapes
A = [1 2 3];
B = [1; 2; 3];
tf = isequal(A, B)Expected output:
ans = logical
0Comparing multiple arrays at once
tf = isequal([1 2], [1 2], [1 2])Expected output:
ans = logical
1NaN values are not equal
tf = isequal(NaN, NaN)Expected output:
ans = logical
0Verifying that every cell starts with []
C = cell(2, 2);
tf = isequal(C{1,1}, [], C{2,2}, [])Expected output:
ans = logical
1Compare exact numeric values across classes
tf = isequal(uint64(255), int16(255), 255, single(255))Expected output:
tf = trueCompare nested resident values without changing their residency
G = gpuArray(uint16([1 2]));
tf = isequal({G}, {uint16([1 2])})Expected output:
tf = trueUsing isequal with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how isequal changes the result.
Run a small isequal example, explain the result, then change one input and compare the output.
FAQ
How is isequal different from ==?⌄
isequal returns a single logical value indicating whether all inputs are completely identical. The == operator performs element-wise comparison and returns an array of the same size as the inputs.
How does isequal handle NaN values?⌄
NaN values are NOT considered equal. isequal(NaN, NaN) returns false. Use isequaln if you want NaN values to be treated as equal.
Can I compare more than two arrays?⌄
Yes. isequal(A, B, C, ...) accepts any number of inputs and returns true only if all inputs are equal to each other.
Are empty arrays equal?⌄
Empty arrays with the same shape are equal. For example, isequal([], []) returns true, and isequal(zeros(0,3), zeros(0,3)) returns true.
How are cell arrays compared?⌄
Cell arrays are compared element-by-element. Each corresponding pair of cells must contain equal values for the cell arrays to be equal.
What happens with different data types?⌄
Numeric classes compare by exact value, including signed and unsigned integers, floating-point values, logical values and character codes. Values are not preconverted through double; other unlike value kinds return false.
Related Logical functions
Source you can read
Every RunMat function's source is public. Read exactly how isequal is executed, line by line, in Rust.
- View the source for isequal in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.