<< Chapter < Page Chapter >> Page >
This module covers basic use of MATLAB, and you will be up and running on variables, matrices, mathematical operations and the built-in help system in just a few minutes.

Matlab help

MATLAB has a great on-line help system accessible using the help command. Typing


will return text information about the chosen function. For example to get information about the built-infunction sum type:

help sum

To list the contents of a toolbox type help<toolbox>, e.g. to show all the functions of the signal processing toolbox enter

help signal processing

If you don't know the name of the function but a suitable keyword use the lookfor followed by a keyword string, e.g.

lookfor 'discrete fourier'

To explore the extensive help system use the "Help menu" or try the commands helpdesk or demo .

Matrices, vectors and scalars

MATLAB uses matrices as the basic variable type. Scalars and vectors are special cases of matrices having size 1x1,1xN or Nx1. In MATLAB, there are a few conventions for entering data:

  • Elements of a row are separated with blanks or commas.
  • Each row is ended by a semicolon, ;.
  • A list of elements must be surrounded by square brackets, [ ]

It is easy to create basic variables.

x = 1 (scalar)

y = [2 4 6 8 10] (row vector)

z = [2; 4; 6; 8; 10] (column vector)

A = [4 3 2 1 0; 1 3 5 7 9] (2 x 5 matrix)

Regularly spaced values of a vector can be entered using the following compact notation


A more compact way of entering variables than in Example 1 is shown here:

y= 2 : 2 : 10


If the skip is omitted it will be set to 1, i.e., the following are equivalent

start:1:end and start:end

To create a string use the single quotation mark " ' ", e.g. by entering x = 'This is a string' .

Indexing matrices and vectors

Indexing variables is straightforward. Given a matrix M the element in the i'th row, j'th column is given by M(i,j) . For a vector v the i'th element is given by v(i) . Note that the lowest allowed index in MATLAB is 1. This is in contrast withmany other programming languages (e.g. JAVA and C), as well as the common notation used in signal processing, where indexing starts at0. The colon operator is also of great help when accessing specific parts of matrices and vectors, as shown below.

This example shows the use of the colon operator for indexing matrices and vectors.

A(1,:) returns the first row of the matrix A.

A(:,3) returns the third column of the matrix A.

A(2,1:5) returns the first five elements of the second row.

x(1:2:10) returns the first five odd-indexed elements of the vector x.

Basic operations

MATLAB has built-in functions for a number of arithmetic operations and functions. Most of them arestraightforward to use. The Table below lists the some commonly used functions. Let x and y be scalars, M and N matrices.

Common mathematical operations in matlab
x y x*y
x y x^y
e x exp(x)
log( x ) log10(x)
ln( x ) log(x)
log2( x ) log2(x)
M -1 inv(M)
M T M'
det( M ) det(M)

  • Dimensions - MATLAB functions length and size are used to find the dimensions of vectors and matrices, respectively.
  • Elementwise operations - If an arithmetic operation should be done on each component in a vector (or matrix), rather than on thevector (matrix) itself, then the operator should be preceded by ".", e.g .*, .^ and ./.

Elementwise operations, part I

Let A 1 1 1 1 . Then A^2 will return AA 2 2 2 2 , while A.^2 will return 1 2 1 2 1 2 1 2 1 1 1 1 .

Elementwise operations, part II

Given a vector x, and a vector y having elements y n 1 x n . This can be easily be done in MATLAB by typing y=1./sin(x) Note that using / in place of ./ would result in the (common) error Matrix dimensions must agree .

Complex numbers

MATLAB has excellent support for complex numbers with several built-in functions available. The imaginaryunit is denoted by i or (as preferred in electrical engineering) j . To create complex variables z 1 7 and z 2 2 e simply enter z1 = 7 + j and z2 = 2*exp(j*pi)

The Table below gives an overview of the basic functions for manipulating complex numbers, where z is a complex number.

Manipulating complex numbers in matlab
Re( z ) real(z)
Im( z ) imag(z)
z abs(z)
Angle( z ) angle(z)
z * conj(z)

Other useful details

  • A semicolon added at the end of a line tells MATLAB to suppress the command output to the display.
  • MATLAB and case sensitivity . For variables MATLAB is case sensitive, i.e., b and B are different. For functions it is case insensitive,i.e., sum and SUM refer to the same function.
  • Often it is useful to split a statement over multiple lines. To split a statement across multiple lines, enter three periods "..." at the end of the line to indicate that it continues on the next line.

Splitting y a b c over multiple lines. y = a... + b...+ c;

Questions & Answers

do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
Do somebody tell me a best nano engineering book for beginners?
s. Reply
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
what's the easiest and fastest way to the synthesize AgNP?
Damian Reply
types of nano material
abeetha Reply
I start with an easy one. carbon nanotubes woven into a long filament like a string
many many of nanotubes
what is the k.e before it land
what is the function of carbon nanotubes?
I'm interested in nanotube
what is nanomaterials​ and their applications of sensors.
Ramkumar Reply
what is nano technology
Sravani Reply
what is system testing?
preparation of nanomaterial
Victor Reply
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
Himanshu Reply
good afternoon madam
what is system testing
what is the application of nanotechnology?
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
anybody can imagine what will be happen after 100 years from now in nano tech world
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
silver nanoparticles could handle the job?
not now but maybe in future only AgNP maybe any other nanomaterials
I'm interested in Nanotube
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Berger describes sociologists as concerned with
Mueller Reply
Got questions? Join the online conversation and get instant answers!
QuizOver.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Engineering computation for power engineers. OpenStax CNX. Oct 28, 2010 Download for free at http://cnx.org/content/col11234/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Engineering computation for power engineers' conversation and receive update notifications?