You are on page 1of 15

Communication System

LAB
Lab # 2
Basics
• The name MATLAB stands for matrix laboratory.
• MATLAB was originally written to provide easy access to matrix
software developed by the LINPACK and EISPACK projects, which
together represent the state-of-the-art in software for matrix
computation.
Help required in MATLAB
• You need help for finding mean

• Simply type in command window :


help mean

• For more details type


doc mean
Refresh MATLAB whenever you need
• Type the following
clear all
close all
clc

• clear all will clear all variables ,functions from your workspace
• close all will close any additional windows , figures etc
• clc will clear command window
Row and column separation
• Row Separation
• Write a=[1,4,5] in command window.
• The result displayed is a row vector
• The comma is used to separate various
elements in a row

• POINT TO BE NOTED : Variables which you assign are case sensitive


Row and column separation
• Column Separation
• Write b=[1;2;3] in command window.
• The result displayed is a Column vector
• The semi colon shown is used to separate various rows
How to refer to a specific element

• Now if you need to use the last element in a=[1,4,5]


Simply type a(end) and enter
• Now if you need to refer to the second last element
Simply type a(end-1) and enter
• Now if you need to refer to the Third last element
Simply type a(end-2) and enter
Logical Indexing
• Lets say c=[1,3,5,8,10]
• Now you need values only which are greater
than 5
• Type c(c>5)
• Type c(c<=5)
Row and column separation
• Column Separation
• Type A=[1,2,3;4,5,6;7,8,9] in command window.
• The result displayed is a Matrix of 3x3
• The complete details are being shown in workspace
If you do not want to display data in
command window. What should you do ?
• Type B=[1,2,3;4,5,6;7,8,9]; in command window.
• The only difference from the previous slide is that we have added a
semicolon at the end after the square bracket and assigned a new
variable B
• You get literally nothing after pressing enter.
• Nothing to Worry you have already assigned it
to a variable named B
• So type B in command window and press enter.
Another way to look for variable B
• Double click on the variable B in the workspace
Basic Mathematical Operations
Scalar Operations include
•+ - * / ^
• log , exp , pow, sqrt , sin , cos ,tan, asin , acos, atan
Special Variables include
Pi (the number 3.142)
i (Imaginary unit)
ans (Last displayed result)
realmax (Largest real number)
intmax (Largest integer)
Lets use some of them (Addition)
• Lets add 2 numbers say 7 +2
• Type 7+2 in command window
• You get 9 which automatically gets a variable name as ans by MATLAB
itself
Lets try exp now
• Type a = [1,4,5]; in command window a row vector is formed
• Now type exp(a)
• We get a row vector
Try pi
• Type pi and enter in command window
• If you type for example pi = 8 the original
pi value will be overwritten and now MATLAB
will store pi as 8
• So to restore original value of pi to 3.1416 simply
type clear pi and then enter pi

You might also like