You are on page 1of 5

TITLE: INTRODUCTION TO MATLAB PROGRAMMING

Table of Contents
OBJECTIVE .........................................................................................................................................................................................1

THEORY .............................................................................................................................................................................................1

FEATURES OF MATLAB ....................................................................................................................................................................... 1


USE OF SEMICOLON (;) IN MATLAB..................................................................................................................................................... 2
NAMING VARIABLES............................................................................................................................................................................... 2
CREATING MATRICES ............................................................................................................................................................................ 2
COMMANDS FOR MANAGING A SESSION .............................................................................................................................................. 2
MULTIDIMENSIONAL ARRAYS ................................................................................................................................................................ 2
COMMENT ................................................................................................................................................................................................ 2

PROGRAMMERS ................................................................................................................................................................................3

ADDING TWO NUMBERS............................................................................................................................................................................... 3


MULTIPLYING TWO NUMBERS ....................................................................................................................................................................... 3
ADDING MATRIX A OF SIZE 3X3 AND MATRIX B OF SIZE 3X3 ............................................................................................................................... 3
ADDING MATRIX A OF SIZE 2X2 AND MATRIX B OF SIZE 2X2 ............................................................................................................................... 4
SUBTRACTING MATRIX A OF SIZE 3X3 FROM MATRIX B OF SIZE 3X3 ..................................................................................................................... 4
MULTIPLYING MATRIX A OF SIZE 3X3 AND MATRIX B OF SIZE 3X3 ........................................................................................................................ 5
MULTIPLYING MATRIX A OF SIZE 3X2 WITH A INTEGER VALUE.............................................................................................................................. 5

DISCUSSION .......................................................................................................................................................................................5

Objective
 Familiarization with MATLAB interface, workspace, command window
 Basic operation in MATLAB
 Creating and storing new files ,folders and scripts in MATLAB

Theory
MATLAB (matrix laboratory) is a programming language developed by MathWorks. It started out as a matrix programming
language where linear algebra programming was simple. It can be run both under interactive sessions and as a batch
job..

Features of MATLAB
Following are the basic features of MATLAB −
 It is a high-level language for numerical computation, visualization and application development.
 It also provides an interactive environment for iterative exploration, design and problem solving.
 It provides vast library of mathematical functions for linear algebra, statistics, Fourier analysis, filtering,
optimization, numerical integration and solving ordinary differential equations.
 It provides built-in graphics for visualizing data and tools for creating custom plots.
 MATLAB's programming interface gives development tools for improving code quality maintainability and
maximizing performance.
 It provides tools for building applications with custom graphical interfaces.
 It provides functions for integrating MATLAB based algorithms with external applications and languages such as
C, Java, .NET and Microsoft Excel.
The desktop has the following panels –

 Current Folder − This panel allows you to access the project folders and files.
 Command Window − This is the main area where commands can be entered at the command line. It
is indicated by the command prompt (>>).
 Command Window − This is the main area where commands can be entered at the command line. It
is indicated by the command prompt (>>).
 Command History − This panel shows or return commands that are entered at the command line.

Use of Semicolon (;) in MATLAB


Semicolon (;) indicates end of statement. However, if you want to suppress and hide the MATLAB output for
an expression, add a semicolon after the expression.

Naming Variables
Variable names consist of a letter followed by any number of letters, digits or underscore.
MATLAB is case-sensitive.
Variable names can be of any length, however, MATLAB uses only first N characters, where N is given by the
function namelengthmax.

Creating Matrices
A matrix is a two-dimensional array of numbers.
In MATLAB, a matrix is created by entering each row as a sequence of space or comma separated elements,
and end of a row is demarcated by a semicolon.

Commands for Managing a Session


 The who command displays all the variable names you have used.
 The clear command deletes all (or the specified) variable(s) from the memory.
 The clc command clear the window
 The help command Searches for a help topic.

Multidimensional Arrays
An array having more than two dimensions is called a multidimensional array in MATLAB. Multidimensional
arrays in MATLAB are an extension of the normal two-dimensional matrix.
Generally to generate a multidimensional array, we first create a two-dimensional array and extend it.

Comment
 % symbol is used to write comment in MATLAB
Programmers

Adding two numbers


%Script for adding two numbers are given below
clc
clear
a=50;
b=100;
add=a+b
OUTPUT

Multiplying two numbers


%Script for multiplying two numbers are given below
clc
clear
a=5;
b=100;
mul=a*b
OUTPUT

Adding matrix A of size 3X3 and matrix B of size 3X3


%Script for adding matrix A of size 3X3 and matrix B of size 3X3 are given below
clc
clear
a=[1,2,3;4,5,6;7,8,9];
b=[1,1,1;2,2,2;3,3,3];
mat=a+b
OUTPUT
Adding matrix A of size 2X2 and matrix B of size 2X2

%Script for Adding matrix A of size 2X2 and matrix B of size 2X2 are given below
clc
clear
a=[4,4,4;8,8,8];
b=[1,1,1;2,2,2];
mat=a+b

Output

Subtracting matrix A of size 3X3 from matrix B of size 3X3

%Script for subtracting matrix A of size 3X3 from matrix B of size 3X3 are given below
clc
clear
b=[4,4,4;6,6,6;10,10,10];
a=[1,1,1;2,2,2;3,3,3];
matsub=b-a

Output
Multiplying matrix A of size 3X3 and matrix B of size 3X3
%Script for multiplying matrix A of size 3X3 and matrix B of size 3X3 are given below
clc
clear
A=[1,0,0;0,1,0;0,0,1];
B=[3,3,3;5,5,5;7,7,7];
matmul=A*B

output

Multiplying matrix A of size 3X2 with a integer value


%Script for Multiplying matrix A of size 3X2 with a integer value are given below
clc
clear
A=[1,0;0,1;2,3];
mulmatrix=A*5

Output

Discussion
In the first lab of signal analysis we got to know about the importance of MATLAB in engineering and how it is used by
various engineers for making complex task easier where we can also perform simulation and can predict the possible
outcome of our work. There we came to know about various windows layout setting, creating script files & saving script
files on local computer disk so that we can run our entire program anytime. We also learn how to comment in MATLAB
using % symbol. There was problem while running a script file and it was solved with our teacher instruction and finally
we performed addition subtraction as well as multiplication and division of numbers and matrices of various order.

You might also like