The standard tool in most engineering departments โ signal processing, control systems, and numerical computing. Everything in MATLAB is fundamentally a matrix, even a single number.
v = [1 2 3 4]; % a row vector
m = [1 2; 3 4]; % a 2x2 matrix โ semicolons separate rows
size(m) % [2 2]
zeros(3,3) % a 3x3 matrix of all zeros
v(1) % 1 โ MATLAB is 1-indexed, not 0-indexed!
m(2,1) % row 2, column 1 -> 3
v(2:3) % elements 2 through 3 -> [2 3]
m(:,1) % the entire first column
Like R, MATLAB applies math to a whole vector/matrix at once โ no manual loop needed.
v * 2 % every element doubled
v .* v % element-wise multiply (note the DOT โ plain * means matrix multiply)
sum(v) % 10
mean(v) % 2.5
x = 10;
if x > 5
disp('Big')
elseif x > 0
disp('Small positive')
else
disp('Not positive')
end
for i = 1:5
disp(i)
end
function result = add(a, b)
result = a + b;
end
% add(2, 3) -> 5
x = 0:0.1:10;
y = sin(x);
plot(x, y)
xlabel('x'); ylabel('sin(x)'); title('Sine wave')