0% found this document useful (0 votes)
48 views

Matlab Tutorials A Brief Introduction

This document provides an introduction to vectors and matrices in MATLAB. It discusses how to: 1) Create row and column vectors using brackets and separating elements with spaces or commas. 2) Address specific elements of a vector using indexes in parentheses. 3) Perform basic operations on vectors like addition and multiplication with other vectors or scalars. 4) Create and address elements of matrices, which are 2D arrays with rows and columns separated by semicolons or spaces. Matrix operations follow the same rules as vector operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Matlab Tutorials A Brief Introduction

This document provides an introduction to vectors and matrices in MATLAB. It discusses how to: 1) Create row and column vectors using brackets and separating elements with spaces or commas. 2) Address specific elements of a vector using indexes in parentheses. 3) Perform basic operations on vectors like addition and multiplication with other vectors or scalars. 4) Create and address elements of matrices, which are 2D arrays with rows and columns separated by semicolons or spaces. Matrix operations follow the same rules as vector operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

MATLAB TUTORIALS

A BRIEF INTRODUCTION
1
2
VECTORS
A row vector in MATLAB can be created by an explicit list, starting with a
left bracket, entering the values separated by spaces (or commas) and
closing the vector with a right bracket.
A column vector can be created the same way, and the rows are separated
by semicolons.
Example:
>> x = [ 0 0.25*pi 0.5*pi 0.75*pi pi ]
x =
0 0.7854 1.5708 2.3562 3.1416
>> y = [ 0; 0.25*pi; 0.5*pi; 0.75*pi; pi ]
y =
0
0.7854
1.5708
2.3562
3.1416
3
VECTORS (Contd)
Vector Addressing A vector element is addressed in MATLAB
with an integer index enclosed in parentheses.
Example:
>> x(3)
ans =
1.5708 3rd element of vector x
The colon notation may be used to address a block of elements.
(start : increment : end) start is the starting index, increment is the
amount to add to each successive index, and end is the ending index.
A shortened format (start : end) may be used if increment is 1.
Example:
>> x(1:3)
ans =
0 0.7854 1.5708 1st to 3rd elements of vector x

4
VECTORS(Contd)
Some Useful Commands
X= start : end % create row vector x starting with start, counting by one,
ending at end.
X= start : increment: end % create row vector x starting with start, counting
by increment, ending at or before end.
linspace(start , end, number) % create row vector x starting with start,
ending at end, having number elements
length(X) % returns the length of x
y= x % transpose of vector x
dot(x,y) % returns the scalar dot product of vectors x and y
5
ARRAY OPERATIONS
Scalar- Array Mathematics
For addition, subtraction, multiplication, and division of an array by a scalar
simply apply the operations to all elements of the array.
Example:
>>f=[1 2; 3 4]
f=
1 2
3 4
>>g= 2*f-1 note that each elements of the array is
multiplied by 2 and then subtracted by 1
g=
1 3
5 7

6
ARRAY OPERATIONS(contd)
Operations Algebraic form MATLAB
Addition a+b a+b
Subtraction a-b a-b
Multiplication axb a.*b
Division ab a./b
Exponentiation a b a.^b
7
Example:
>>x=[1 2 3];
>>y=[4 5 6]; each element in x is multiplied by the
corresponding element in y.
>>z=x.*y
z=
4 10 18
8
MATRICES
A matrix array is 2-dimensional, having both multiple rows and
multiple columns, similar to vector arrays:
It begins with [, and end with ]
Spaces or commas are used to separate elements in a row
Semicolon is used to separate rows.
Example;>> f= [1 2 3; 4 5 6]
f=
1 2 3
4 5 6

9
Matrix Addressing:
----matrixname( row, column)
----colon may be used in place of a row or
column reference select the entire row
or column
Example:
>>f(2,3)
ans=6
>>f(:,1)
ans=
1
4
10
............to be contined
11

You might also like