MATLAB Cheatsheet - MATLAB Commands & Matrix Operations Reference
This reference is for engineers and scientists who think in matrices rather than element loops. It covers building matrices and vectors, in-place operations like transpose and eigenvalue decomposition, statistical summaries, plotting curves and surfaces, file read/write, and FFT-based signal analysis. Unlike numpy the commands here feel native to the language, so you can type them directly in the Command Window and inspect each result. After reading you should be able to assemble a matrix, transpose/invert/decompose it, turn a vector into a plot, and save the intermediate result with save/load.
Matrix Creation 8
A = [1 2 3; 4 5 6; 7 8 9]B = [1; 2; 3]C = [1, 2, 3]D = zeros(3, 4)E = ones(2, 3)F = eye(3)G = rand(3, 3)H = linspace(0, 10, 100)Matrix Operations 11
A'inv(A)det(A)rank(A)trace(A)eig(A)svd(A)A * BA .* BA / BA \ BData Visualization 16
plot(x, y)scatter(x, y)bar(x, y)hist(data)pie(data)surf(X, Y, Z)mesh(X, Y, Z)contour(X, Y, Z)title("Chart Title")xlabel("X Axis")ylabel("Y Axis")legend("Curve 1", "Curve 2")grid onhold onhold offsubplot(2, 2, 1)Data Processing 12
mean(A)median(A)std(A)var(A)max(A)min(A)sum(A)cumsum(A)diff(A)sort(A)unique(A)find(A > 5)File I/O 10
load("data.mat")save("data.mat", "var")data = csvread("file.csv")csvwrite("file.csv", data)data = xlsread("file.xlsx")xlswrite("file.xlsx", data)fid = fopen("file.txt", "r")fclose(fid)fscanf(fid, "%f", [1, inf])fprintf(fid, "%f\n", data)Programming Basics 10
for i = 1:10 ... endwhile condition ... endif condition ... elseif ... else ... endswitch expr case val1 ... otherwise ... endfunction [out] = func(in) ... end% comment%{ block comment %}disp("message")fprintf("format %d\n", var)input("Prompt: ")Linear Algebra 9
A * x = bx = A \ b[L, U, P] = lu(A)[Q, R] = qr(A)[U, S, V] = svd(A)norm(A)cond(A)null(A)orth(A)Signal Processing 7
fft(x)ifft(X)conv(x, y)xcorr(x, y)filter(b, a, x)spectrogram(x)psd(x)Tips
- MATLAB indices start at 1, not 0 (unlike Python/C).
- Matrix multiply uses *; element-wise uses .* - keep them distinct.
- plot connects points into a curve; scatter draws individual points.
- hold on overlays multiple curves on one figure; hold off releases it.
- load/save default to MAT format; use csvread/csvwrite for CSV.
- A function file must match the function name, e.g. myfunc.m for function myfunc.
- Use help to view function docs, e.g. help plot.
- Use doc to open full documentation, e.g. doc plot.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us