Plain scripts (.m)
Open any .m file and it is shown with its %% sections, which you run one at a time. A comment right after %% becomes the section title, and comment lines below it become formatted text. Create one with New › Script (.m) (Ctrl+Alt+N).
Functions defined at the end of a script can be called from any section. Function files and classes in the same folder as the script are found automatically, as in MATLAB.
%% Solving a linear system
% Results appear right below the code.
A = [4 -2 1; -2 4 -2; 1 -2 4];
rhs = [11; -16; 17];
sol = A \ rhs
residual = norm(A*sol - rhs)
%% A local function
n = 1:10;
f = arrayfun(@fib, n)
function r = fib(n)
if n <= 2
r = 1;
else
r = fib(n - 1) + fib(n - 2);
end
end