English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

MATLAB Commands

MATLAB is an interactive program for numerical computation and data visualization. You can enter commands by typing them into the MATLAB prompt '>>' in the command window.

In this section, we will provide a list of commonly used general MATLAB commands.

Session management commands

MATLAB provides various commands for managing sessions. The following table provides all such commands-

CommandPurpose
clcClear the command window.
clearDelete variables from memory.
existCheck for the existence of files or variables.
globalDeclare variables as global variables.
helpSearch for help topics.
lookforSearch for keywords in the help entries.
quitStop MATLAB.
whoList current variables.
whosList current variables (long display).

System commands

MATLAB provides various useful commands to handle the system, such as saving the current workspace as a file and loading the file later.

It also provides various commands for other system-related activities, such as displaying the date, listing files in the directory, and displaying the current directory, etc.

The following table displays some commonly used system-related commands-

CommandPurpose
cdChange the current directory.
dateDisplay the current date.
deleteDelete files.
diaryEnable/Stop recording diary file.
dirList all files in the current directory.
loadLoad workspace variables from a file.
pathDisplay the search path.
pwdDisplay the current directory.
saveSave workspace variables to a file.
typeDisplay the content of the file.
whatList all MATLAB files in the current directory.
wklreadRead .wk1Spreadsheet files.

Input and output commands

MATLAB provides the following commands related to input and output-

CommandPurpose
dispDisplay the content of an array or string.
fscanfRead formatted data from a file.
formatControl the display format of the screen.
fprintfExecute formatted writing to the screen or file.
inputDisplay a prompt and wait for input.
;Prohibit screen printing.

fscanfandfprintfThe behavior of the command is like the C scanf and printf functions. They support the following format codes-

Format codePurpose
%sFormat as a string.
%dFormat as an integer.
%fFormat as a floating-point value.
%eFormat as a floating-point value in scientific notation.
%gFormat in the most compact format: %f or %e.
\nInsert a new line in the output string.
\tInsert a tab in the output string.

The format function has the following form for displaying numbers-

Format functionMaximum display
format short

Four decimal places (default).

format long

16Number of decimal places.

format short eFive digits plus exponent.
format long e16Number of digits plus exponent.
format bankTwo decimal places. Fixed-point currency format
format +Positive number, negative number, or zero.
format ratRational approximation. Decimal fraction representation
format compactProhibit certain line breaks.
format looseReset to a less compact display mode.

Vector, matrix, and array commands

The following table shows various commands used for processing arrays, matrices, and vectors-

CommandPurpose
catConcatenate arrays.
findFind the index of non-zero elements.
lengthCalculate the number of elements.
linspaceCreate a vector with regular spacing.
logspaceCreate a vector with logarithmic spacing.
maxReturn the largest element.
minReturn the smallest element.
prodProduct of each column.
reshapeChange size.
sizeCalculate the size of an array.
sortSort each column.
sumSum each column.
eyeCreate a unit matrix.
onesCreate an array.
zerosCreate a zero array.
crossCalculate the cross product of a matrix.
dotCalculate the dot product of a matrix.
detCalculate the determinant of an array.
invCalculate the inverse of a matrix.
pinvCalculate the pseudoinverse of a matrix.
rankCalculate the rank of a matrix.
rrefCalculate the reduced row echelon form of a matrix.
numCreate a cell array.
celldispDisplay the cell array.
cellplot

Display the graphical representation of a cell array.

num2numcell
Convert a numeric array to a cell array.deal
Match input and output lists.

Identify cell array.

Plotting Commands

MATLAB provides many commands for plotting graphics. The following table shows some commonly used plotting commands-

CommandPurpose
axisSet axis limits.
fplot

Intelligent plotting of functions.

gridShow grid lines.
plotGenerate an xy plot.
printPrint the graph or save it to a file.
titlePlace text at the top of the graph.
xlabelAdd text labels to the x-axis.
ylabelAdd text labels to the y-axis.
axesCreate an axis object.
closeClose the current graph.
close allClose all plots.
figureOpen a new graph window.
gtextEnable label placement with the mouse.
holdFreeze the current graph.
legendPlace the legend with the mouse.
refreshRedraw the current graph window.
setSpecify the properties of an object (e.g., axis).
subplotCreate a plot in a subwindow.
textPlace a string in the graph.
barCreate a bar plot.
loglogCreate a logarithmic plot.-Logarithmic plot.
polarCreate a polar plot.
semilogxCreate a semi-log plot. (Logarithmic X-axis).
semilogyCreate a semi-log plot. (Logarithmic Y-axis).
stairsCreate a staircase plot.
stemCreate a stem plot.