MATLAB Operators and Special Characters
This page contains a comprehensive listing of all MATLAB® operators, symbols, and special characters.
Arithmetic Operators
Symbol | Role |
---|---|
+ | Addition |
+A | Unary plus |
- | Subtraction |
-A | Unary minus |
.* | Element-wise multiplication |
* | Matrix multiplication |
./ | Element-wise right division |
/ | Matrix right division |
.\ | Element-wise left division |
\ | Matrix left division (also known as backslash) |
.^ | Element-wise power |
^ | Matrix power |
.' | Transpose |
' | Complex conjugate transpose |
Relational Operators
Logical Operators
Special Characters
Symbol | Role |
---|---|
@ | Create anonymous functions and function handles, call superclass methods |
. | Decimal point, element-wise operations, indexing |
... | Line continuation |
, | Separate row elements in an array, array subscripts, function input and output arguments, commands entered on the same line |
: | Vector creation, for-loop iteration, indexing |
; | Separate rows in an array creation command, suppress output of a line of code |
( ) | Operator precedence, function argument enclosure, indexing |
[ ] | Array construction and concatenation, empty matrix creation, element deletion, multiple output argument assignment |
{ } | Create cell array, indexing |
% | Code comments, conversion specifier |
{% %} | Block of comments that extend beyond one line |
! | Issue operating system command |
? | Retrieve metaclass information for class name |
'' | Create character array |
"" | Create string |
~ | Represent logical NOT, suppress specific input or output arguments. |
= | Variable creation and indexing assignment. The
|
<
& | Specify one or more superclasses in a class definition. |
.? | Specify the fields of a name-value structure as the names of all writeable properties of the class. |
String and Character Formatting
Some special characters can only be used in the text of a character vector or string. You can use these special characters to insert new lines or carriage returns, specify folder paths, and more.
Use the special characters in this table to specify a folder path using a character vector or string.
| Name: Slash and Backslash Uses: File or folder path separation Description: In addition to their use as mathematical operators, the slash and backslash characters separate the elements of a path or folder. On Microsoft® Windows® based systems, both slash and backslash have the same effect. On The Open Group UNIX® based systems, you must use slash only. Examples On a Windows system, you can use either backslash or slash: dir([matlabroot '\toolbox\matlab\elmat\shiftdim.m']) dir([matlabroot '/toolbox/matlab/elmat/shiftdim.m']) On a UNIX system, use only the forward slash: dir([matlabroot '/toolbox/matlab/elmat/shiftdim.m'])
|
.. | Name: Dot dot Uses: Parent folder Description: Two dots in succession refers to the parent of the current folder. Use this character to specify folder paths relative to the current folder. Examples To go up two levels in the
folder tree and down into the cd ..\..\test More Information
|
* | Name: Asterisk Uses: Wildcard character Description: In addition to being the symbol for
matrix multiplication, the asterisk Wildcards are generally
used in file operations that act on multiple files or folders.
MATLAB matches all characters in the name exactly except
for the wildcard character Examples Locate all files with names
that start with dir('january_*.mat') |
@ | Name: At symbol Uses: Class folder indicator Description: An Examples Refer to a class folder: \@myClass\get.m More Information
|
+ | Name: Plus Uses: Namespace directory indicator Description: A Examples Namespace
folders always begin with the +myfolder +myfolder/pkfcn.m % a namespace function +myfolder/@myClass % class folder in a namespace More Information
|
There are certain special characters that you cannot enter as ordinary text.
Instead, you must use unique character sequences to represent them. Use the symbols
in this table to format strings and character vectors on their own or in conjunction
with formatting functions like compose
, sprintf
, and error
. For more information, see Formatting Text.
Symbol | Effect on Text |
---|---|
'' | Single quotation mark |
%% | Single percent sign |
\\ | Single backslash |
\a | Alarm |
\b | Backspace |
\f | Form feed |
\n | New line |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\xN | Hexadecimal number, |
\N | Octal number, |