You are on page 1of 6

Vector operation

Matlab provides a wide range of operations for manipulating vectors. Here are some common vector
operations in Matlab:

Creating a vector:

You can create a row or column vector in Matlab using square brackets and separating the elements
with spaces or commas.

For example, x = [1 2 3] creates a row vector with elements 1, 2, and 3.

Vector addition and subtraction: You can add or subtract two vectors of the same size by using the plus
or minus sign, respectively. For example, y = x + [4 5 6] creates a new vector y with elements equal to
the sum of the corresponding elements of x and [4 5 6].

Scalar multiplication and division:

You can multiply or divide a vector by a scalar using the asterisk or slash sign, respectively.

For example, z = 2*x creates a new vector z with elements twice the corresponding elements of x.

Dot product:

You can compute the dot product of two vectors by using the dot function. For example, dp = dot(x, y)
computes the dot product of vectors x and y.

Cross product:

You can compute the cross product of two vectors by using the cross function. For example, cp = cross(x,
y) computes the cross product of vectors x and y.

Display command

In Matlab, the ‘disp’ command is used to display the value of a variable or a string message to the
command window. Here are some examples of using the ‘disp’ command in Matlab:

Displaying a string message:

disp ('Hello, world!')

Displaying a variable:

x = 10;

disp(x)

Transport of vector

2020-ME-511
In Matlab, you can transport a vector using the transpose operator, which is denoted by an apostrophe
(') or the transpose function transpose () or .'.

Transposing a vector flips it along its diagonal, swapping its rows and columns.

x = [1 2 3];

y = x';

x = [1 2 3];

y = transpose(x);

x = [1 2 3];

y = x.';

This will create a column vector y by transposing the row vector x using this all function.

Semi colon

In Matlab, the semicolon (;) is a statement terminator.

It is used to suppress the output of a statement or command, meaning that the result of that statement
will not be displayed in the command window or console.

Who command

In MATLAB, the "who" command is used to list the variables that are currently defined in the workspace.
When you type "who" in the Command Window, MATLAB displays a list of all the variables that you
have defined during your current session.

Whos command

In MATLAB, the "whos" command is similar to the "who" command, but it provides more detailed
information about the variables in the workspace, such as their sizes and data types. When you type

2020-ME-511
"whos" in the Command Window, MATLAB displays a table of information about all the variables that
you have defined during your current session.

Determinant of matrix

In MATLAB, you can use the ‘det’ function to compute the determinant of a matrix. Here's how you can
use the ‘det’ function:

Inverse of matrix

In MATLAB, you can use the ‘inv’ function to compute the inverse of a matrix. Here's how you can use
the ‘inv’ function:

Zeros

Produce N by N matrix of zeros.

Produce N by M matrix of zeros.

Ones

Produce N by N matrix of ones.

Produce N by M matrix of ones.

2020-ME-511
Mean

Size

2020-ME-511
Return the size (dimensions) of matrix x.

Length

Return the length (number of elements) of vector v.

Maximum

Find the largest element in a matrix or a vector.

2020-ME-511
Minimum

Find the smallest element in a matrix or a vector.

Product

Product of the elements of x.

For matrices, Prod(x) is a row vector with the product over each column.

The colon " : " is one of the most important MATLAB operators.

It occurs in several different forms.

The expression >> 1:10 is a row vector containing the integers from 1 to 10

1 2 3 4 5 6 7 8 9 10

To obtain nonunit spacing, specify an increment.

For example,

>> 100:-7:50

100 93 86 79 72 65 58 51

2020-ME-511

You might also like