
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Commands
MATLAB is an interactive program for numerical computation and data visualization. You can enter a command by typing it at the MATLAB prompt '>>' on the Command Window.
In this section, we will provide lists of commonly used general MATLAB commands.
Commands for Managing a Session
MATLAB provides various commands for managing a session. The following table provides all such commands −
Command | Purpose |
---|---|
clc | Clears command window. |
clear | Removes variables from memory. |
exist | Checks for existence of file or variable. |
global | Declares variables to be global. |
help | Searches for a help topic. |
lookfor | Searches help entries for a keyword. |
quit | Stops MATLAB. |
who | Lists current variables. |
whos | Lists current variables (long display). |
Commands for Working with the System
MATLAB provides various useful commands for working with the system, like saving the current work in the workspace as a file and loading the file later.
It also provides various commands for other system-related activities like, displaying date, listing files in the directory, displaying current directory, etc.
The following table displays some commonly used system-related commands −
Command | Purpose |
---|---|
cd | Changes current directory. |
date | Displays current date. |
delete | Deletes a file. |
diary | Switches on/off diary file recording. |
dir | Lists all files in current directory. |
load | Loads workspace variables from a file. |
path | Displays search path. |
pwd | Displays current directory. |
save | Saves workspace variables in a file. |
type | Displays contents of a file. |
what | Lists all MATLAB files in the current directory. |
wklread | Reads .wk1 spreadsheet file. |
Input and Output Commands
MATLAB provides the following input and output related commands −
Command | Purpose |
---|---|
disp | Displays contents of an array or string. |
fscanf | Read formatted data from a file. |
format | Controls screen-display format. |
fprintf | Performs formatted writes to screen or file. |
input | Displays prompts and waits for input. |
; | Suppresses screen printing. |
The fscanf and fprintf commands behave like C scanf and printf functions. They support the following format codes −
Format Code | Purpose |
---|---|
%s | Format as a string. |
%d | Format as an integer. |
%f | Format as a floating point value. |
%e | Format as a floating point value in scientific notation. |
%g | Format in the most compact form: %f or %e. |
\n | Insert a new line in the output string. |
\t | Insert a tab in the output string. |
The format function has the following forms used for numeric display −
Format Function | Display up to |
---|---|
format short | Four decimal digits (default). |
format long | 16 decimal digits. |
format short e | Five digits plus exponent. |
format long e | 16 digits plus exponents. |
format bank | Two decimal digits. |
format + | Positive, negative, or zero. |
format rat | Rational approximation. |
format compact | Suppresses some line feeds. |
format loose | Resets to less compact display mode. |
Vector, Matrix and Array Commands
The following table shows various commands used for working with arrays, matrices and vectors −
Command | Purpose |
---|---|
cat | Concatenates arrays. |
find | Finds indices of nonzero elements. |
length | Computes number of elements. |
linspace | Creates regularly spaced vector. |
logspace | Creates logarithmically spaced vector. |
max | Returns largest element. |
min | Returns smallest element. |
prod | Product of each column. |
reshape | Changes size. |
size | Computes array size. |
sort | Sorts each column. |
sum | Sums each column. |
eye | Creates an identity matrix. |
ones | Creates an array of ones. |
zeros | Creates an array of zeros. |
cross | Computes matrix cross products. |
dot | Computes matrix dot products. |
det | Computes determinant of an array. |
inv | Computes inverse of a matrix. |
pinv | Computes pseudoinverse of a matrix. |
rank | Computes rank of a matrix. |
rref | Computes reduced row echelon form. |
cell | Creates cell array. |
celldisp | Displays cell array. |
cellplot | Displays graphical representation of cell array. |
num2cell | Converts numeric array to cell array. |
deal | Matches input and output lists. |
iscell | Identifies cell array. |
Plotting Commands
MATLAB provides numerous commands for plotting graphs. The following table shows some of the commonly used commands for plotting −
Command | Purpose |
---|---|
axis | Sets axis limits. |
fplot | Intelligent plotting of functions. |
grid | Displays gridlines. |
plot | Generates xy plot. |
Prints plot or saves plot to a file. | |
title | Puts text at top of plot. |
xlabel | Adds text label to x-axis. |
ylabel | Adds text label to y-axis. |
axes | Creates axes objects. |
close | Closes the current plot. |
close all | Closes all plots. |
figure | Opens a new figure window. |
gtext | Enables label placement by mouse. |
hold | Freezes current plot. |
legend | Legend placement by mouse. |
refresh | Redraws current figure window. |
set | Specifies properties of objects such as axes. |
subplot | Creates plots in subwindows. |
text | Places string in figure. |
bar | Creates bar chart. |
loglog | Creates log-log plot. |
polar | Creates polar plot. |
semilogx | Creates semilog plot. (logarithmic abscissa). |
semilogy | Creates semilog plot. (logarithmic ordinate). |
stairs | Creates stairs plot. |
stem | Creates stem plot. |