numbl implements a substantial subset of the MATLAB language.
| Category | Operators |
|---|---|
| Arithmetic | + - * / \ ^ .* ./ .\ .^ |
| Comparison | == ~= < <= > >= |
| Logical | && || & | ~ xor |
| Transpose | ' .' |
| Type | Status |
|---|---|
| double | Default numeric type |
| logical | Supported |
| char | Supported ('text') |
| string | Supported ("text") |
| complex | Full support throughout |
| cell | Supported |
| struct | Supported |
| sparse | Supported (real and complex, CSC format) |
| function_handle | Supported |
| class instances | Supported (value and handle classes) |
| dictionary | Supported (MATLAB R2022b+ feature) |
Integer types (int8, uint16, etc.) and single-precision are not supported.
All standard MATLAB control flow is supported:
% if / elseif / else
if x > 0
disp('positive');
elseif x < 0
disp('negative');
else
disp('zero');
end
% for loops
for i = 1:10
fprintf('%d ', i);
end
% while loops
while n > 1
n = n / 2;
end
% switch / case
switch color
case 'red', code = 1;
case 'blue', code = 2;
otherwise, code = 0;
end
% try / catch
try
result = riskyOperation();
catch e
fprintf('Error: %s\n', e.message);
end
break, continue, and return work as expected.
% Regular function
function result = add(a, b)
result = a + b;
end
% Multiple return values
[q, r] = quorem(17, 5);
% Anonymous functions
f = @(x) x.^2 + 1;
% Function handles
g = @sin;
% Variable arguments
function out = flexible(varargin)
out = nargin;
end
Nested functions and subfunctions are supported.
classdef Point
properties
x
y
end
methods
function obj = Point(x, y)
obj.x = x;
obj.y = y;
end
function d = dist(obj)
d = sqrt(obj.x^2 + obj.y^2);
end
end
methods (Static)
function p = origin()
p = Point(0, 0);
end
end
end
Inheritance, abstract classes, enumerations, and both value and handle classes are supported.
A = [1 2 3; 4 5 6]; % Matrix literal
v = 1:0.5:10; % Colon range
A(end, :) % end indexing
A(A > 3) % Logical indexing
c = {1, 'hello', [1 2]}; % Cell array
s.name = 'test'; % Struct
s.(fieldName) % Dynamic field access
% Line comment
x = 1; % Inline comment
%{
Block comment
spanning multiple lines
%}
function count()
persistent n
if isempty(n)
n = 0;
end
n = n + 1;
disp(n);
end
Notable MATLAB features not yet implemented:
parfor, spmd)