You are on page 1of 18

MATLAB

Matlab is basically a high level


language which has many specialized
toolboxes for making things easier for
us
How high?

Command Line

Current Directory

New Script


No need to type



We can write it as
Example:-
X=5;
Y=7;
Or Simply
syms X Y % not require commas in b/w var.

Syntax for
comment
%
1D-array:-
Ex:-
a= [1 1 1 1 1];

2D-array:-
A=[1 1 1 1;1 1 1 1;1 1 1 1 ;1 1 1 1];
Equivalent to:-
A=[1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1]



Display(hello); % After run. Display hello
in command line.

A=input(); %input from user to the var.

Display(A); %display content of var A.
fprintf(); % display content of var A.


Difference ?
+ addition
- subtraction
* multiplication
/ division
^ power
complex conjugate transpose %not for our
purpose.

Example:-






Output ??
end is closing
of switch case.
Similar to C.
Closing of if , else statement is with end.
Example:-
for i=1:N
.

end

while(condition)
..

end

function [A,B ] = Check( X,Y)

A=2*X;
B=2*Y;
end

OUTPUT=>
[x,y]=Check(2,3)
x=4
y=6;
syms x y
[x,y]=Check(2,3);
display(x);
display(y);
Name of script file is chetan2.m
Whenever in command window you type chetan2, the
script code will be executed.

>> chetan2

x =

4


y =

6
Many things remains same as c
E.g:-
1- break;
2-continue;
3- ==
4- &&
BUT!!!
5- ! This is replaced by ~
6-syms is used to define variable no use of int,float
7-zeros(1,N) create the matrix which has 1row and
N column in which all element are zero
A=zeros(5);
Create the matrix of 5X5

Simple command
plot(X,Y,r);
Eg.:-
X=[2 3 5 4 5 4 6 2];
Y=[2 5 3 4 5 8 9 3];
Plot(X,Y);
It will crate

Plotting of multiple graph on one graph
syms X Y
X = linspace(0,2*pi,200);
plot(X,sin(X),'b');
hold on
plot(X,cos(X),'r-');
hold off

You might also like