100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

MATLAB Cheat Sheet

MATLAB Cheat Sheet

Key MATLAB syntax for matrices, control flow, function definitions, and plotting used in numerical computing.

2 PagesBeginnerApr 15, 2026

Basics

Variables and output.

matlab
% Variables and basic I/Ox = 42;name = 'MATLAB';disp(x)fprintf('Value: %d\n', x)y = 3.14   % without semicolon, prints result

Matrices

Creating and operating on matrices.

matlab
A = [1 2 3; 4 5 6; 7 8 9];   % 3x3 matrixB = zeros(3,3);C = A';                       % transposeD = A * B;                    % matrix multiplicationE = A .* A;                   % element-wise multiplicationv = A(2,:);                   % second roww = A(:,1);                   % first columninvA = inv(A);                % matrix inverse (if invertible)

Control Flow

Loops and conditionals.

matlab
for i = 1:5    fprintf('i = %d\n', i);endx = 10;if x > 5    disp('big')elseif x == 5    disp('equal')else    disp('small')endwhile x > 0    x = x - 1;end

Functions

Defining and calling functions.

  • function y = f(x)- Defines a function; typically one per .m file
  • nargin / nargout- Number of input/output arguments actually supplied
  • anonymous function- f = @(x) x^2; creates an inline function handle
  • size(A) / length(v)- Dimensions of a matrix / length of a vector
  • disp / fprintf- Print a value / print formatted text

Plotting

Basic 2D plotting.

matlab
x = linspace(0, 2*pi, 100);y = sin(x);plot(x, y)xlabel('x')ylabel('sin(x)')title('Sine Wave')grid on
Pro Tip

Preallocate arrays with zeros()/ones() before loops — growing arrays dynamically inside a loop is one of the most common MATLAB performance killers.

Was this cheat sheet helpful?

Explore Topics

#MATLAB#MATLABCheatSheet#Programming#Beginner#Matrices#ControlFlow#Functions#Plotting#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet