Important MATLAB Commands
Basic Commands
clc - Clears the Command Window
clear - Removes all variables from the workspace
close all - Closes all figure windows
who / whos - Lists variables in the workspace
help function_name - Shows help for a specific function
doc function_name - Opens documentation for a function
exit / quit - Closes MATLAB
Math Operations
+, -, *, /, .^, .* - Basic arithmetic operations
sqrt(x) - Square root
log(x) / log10(x) - Natural and base-10 logarithm
exp(x) - Exponential (e^x)
round(x), floor(x), ceil(x) - Rounding functions
mod(x, y) - Modulo (remainder)
Plotting and Visualization
plot(x, y) - 2D line plot
subplot(m,n,p) - Creates subplot in grid
title('text') - Adds title to plot
xlabel('x'), ylabel('y') - Labels axes
legend('name1', 'name2') - Adds legend
grid on/off - Toggles grid
figure - Opens new figure window
Matrix and Array Operations
zeros(n), ones(n) - Create n×n matrix of zeros or ones
eye(n) - Identity matrix
size(A) - Returns size of matrix A
length(A) - Length of vector
A' - Transpose of matrix A
inv(A) - Inverse of A
det(A) - Determinant of A
A .* B - Element-wise multiplication
A*B - Matrix multiplication
Loops and Conditionals
Important MATLAB Commands
for i = 1:n ... end - For loop
while condition ... end - While loop
if ... elseif ... else ... end - Conditional statements
switch ... case ... otherwise ... end - Switch-case statement
Functions and Scripts
function y = myFunc(x) - Define a function
script_name - Run a script file
return - Exit a function early
Logical & Relational Operations
==, ~=, >, <, >=, <= - Relational operators
&&, ||, ~ - Logical AND, OR, NOT
find(A) - Indices of non-zero elements
any(A), all(A) - Tests if any or all elements are true
File Handling
load('[Link]') - Load .mat file
save('[Link]') - Save variables to file
fopen, fclose - Open/close file
fprintf, fscanf - Print to/read from file