Matlab

# Special characters in MatLab

Like all programming languages, MATLAB has a set of special characters for interpreting the program. These characters are reserved for the system and cannot be used by the programming user to assign names to variables, functions, or other types of definitions that can be made. These special characters include arithmetic operators, logical operators, etc. Due to its length, in this article, we will only explain in detail what belongs to the special characters and leave the operators to another article.

## List of MATLAB special characters, meaning and application

Below we list each MATLAB special characters and explain their usage and meaning with a brief example.

## MATLAB Special character @ (At symbol)

This symbol is used when creating a function. To do this, the function name must be declared after the “@” symbol.

fhandle = @newfunction

In the case of an anonymous function.

fhandle = @a+b

## MATLAB Special character . (Dot)

The dot separates the whole and fractional parts in decimal values.

1.4142

The dot character also allows you to access the fields of a structure

struct . field

This symbol is also used to access the properties and methods of an object.

object. properties

## Special character … (Dot dot dot or ellipsis)

At the end of a line, this symbol indicates that the current command continues on the next line.

command…

continuation of current command

## MATLAB Special character , (Comma)

This character is used to separate row elements of array subscripts.

q = [ 1, 2, 3, 4; 5, 6, 7, 8 ]

Also, this character is used to separate the different input arguments in a function.

str = strcmp ( s1, s2)

And to separate the different output arguments in a function

[ r, i ] = min(a)

## MATLAB Special character : (Colon)

This character is used for creating vectors.

v = 1 : 5

Also, the colon is used to define the limit in a “for” loop.

for x = 1 : 10

Index a range of elements in a specified dimension:

A (2 : 3, 4)

Assign new elements to an array:

x = [ 1, 2, 3, 4;

5, 6, 7, 8;

1, 2, 3, 4 ]

x (:) = 1: 12

## MATLAB Special character ; (Semicolon)

This character is used to separate the rows in the creation of a matrix

x = [ 1, 2, 3, 4;

5, 6, 7, 8;

1, 2, 3, 4]

It is also used to suppress the output of the current command.

x = 1 2 3;

Or to several separate commands written on a single line

x = 1; a = strcmp(s1, s2); str = strcat (s1, s2);

## MATLAB Special character ( ) (Parentheses)

These characters are used to enclose the input arguments of a function.

a = strcat (s1, s2)

Also, these special characters are used for array indexing.

a (: , 1)

b (2, 1)

They are also used in mathematical operations in operator precedence.

(A.*(B./C)) - D

## MATLAB Special character [ ] (Square brackets)

These special characters are used for the creation of matrices and vectors.

m = [ 1, 2, 3, 4; 5, 6, 7, 8; 1, 2, 3, 4]

v = [1, 2, 3, 4]

Square bracket to capture more than one input argument in a function.

a = magic(5)
[r, i] = min(a)

Square brackets for the creation of an empty array.

a = []

Square bracket to add a new bottom row to an array.

a = magic(5);

a = [a; 4, 5, 8, 3, 2]

Square bracket to remove a matrix column:

a = magic(5);

a (:,1) = []

## MATLAB Special character { } (Curly braces )

These special characters are used in creating cell arrays.

s1 = {' a ',' z ',' h ',' y '}

## MATLAB Special character % (Percent )

The percent character is used to make comments. Everything written after this character on the current line is not considered code by MATLAB and is only useful as programmer annotation.

% This is a comment, it is not part of the program

## MATLAB Special character % { %} (Percent curly bracket)

This character set is used to make comments that extend over more than one line. The %{ and %} operators must appear alone on the lines immediately preceding and following the text block as shown below.

%{

This is a comment.

Everything enclosed within

these curly braces are considered

commentary by MATLAB.

%}

## MATLAB Special character ? (Question Mark )

This character retrieves the meta.class object. This operator only works with a class name, not an object.

?inputParser

## MATLAB Special character ‘ ‘ (Single quotes )

These characters are used to create character vectors with a class of char.

chr = ‘Hello MATLAB’

## MATLAB Special character “ “ (Double quotes )

These characters are used to create strings that have a class of strings.

str = “Hello MATLAB”

## MATLAB Special character “Space“

This character represents a logical NOT.

if ~ strcmp(s1, s2)

Also, this character is used to suppress specific input or output arguments of a function.

[~ , i] = min(a)

## MATLAB Special character = (Equal )

This character assigns values to a variable.

a = 21

The space character is used like commas to separate row elements in the construction of an array.

A = [1 2 3 4;

5 6 7 8]

Also, like commas, it is used to separate the values returned by a function.

[r i] = min(a)

## MATLAB Special character ~ (Tilde )

Also, to store the elements of a in the variable b.

a = b

## MATLAB Special character < & (Left angle bracket and ampersand )

This character set is used to specify superclasses.

classdef MyClass < MySuperclass

And in the definition of a class that derives from a superclass:

classdef MyClass < MySuperclass1 & MySuperclass2 & …

## MATLAB Special character .? (Dot question mark )

This character set specifies the name-value structure fields.

In this case, the field names of the propArgs structure are specified as write properties of the matlab.graphics.primitive.Line class.

function f(propArgs)

arguments

propArgs.? matlab.graphics.primitive.Line

end

end

## Conclusion

In this article, we have shown you the list of MATLAB special characters and explained the meaning of each character with a short example. This programming language also has relational, arithmetic, logical operators, and escape characters, which are covered in our other MATLAB articles. We hope you found this MATLAB article useful. For more tips and information, see other Linux Hint articles. 