AnatomyOf

Anatomy of a MATLAB file

example.m
1%{
2Quick demo: MATLAB, proving since 1984 that real programmers
3do use semicolons -- just to hide the output, not end the line.
4%}
5
6function result = clamp(values, lo, hi)
7 % Vectorized clamp -- no loop in sight, and that's the point
8 result = values;
9
10 if any(result > hi)
11 disp('Clipping values above the ceiling.');
12 result(result > hi) = hi;
13 end
14
15 for i = 1:length(result)
16 if result(i) < lo
17 result(i) = lo;
18 end
19 end
20end
MATLAB is a high-performance language for technical computing, integrating computation, visualization, and programming in an easy-to-use environment.