Anda di halaman 1dari 4

->in command window use up and down arrow to know our prevoius comands

->for imaginary numbers use a+j*b


->for absolute value use abs(c),exp(int) for exponential,sqrt(int) for square root
->MATLAB--matrix laboratory
-> we can create array ,matrix and do operations on them
->in command window type doc command(eg:sin)
we get whole info about that command
->ML suports n dimensional matrix
->n=6.02e23
here n is variable;e23 is e to the power 23;
->creation of matrix
z=[1 2 3;4 5 6;7 8 9]

z =

1 2 3
4 5 6
7 8 9
->>> size(z) to get matrix dimensions;
-> length(z) to get highest dmension of matrix
eg: z =

1
2
3
4
5

>> length(z)

ans =

>> z=[1 2 3 4 5]

z =

1 2 3 4 5

>> length(z)

ans =

5
->use clc to clear screen even though varibles are not deleted;so to delete them
permanently use clear
->to plot a function
t=0:0.01(increment):2*pi(final value);
y=sin(t);
plot(y)
->z=[1 2 3;4 5 6;7 8 9]

z =

1 2 3
4 5 6
7 8 9
to edit elements in row use z(2 , :)=[15 16 17]
z =

1 2 3
15 16 17
7 8 9
to eddit elements in column use z(:,2)=[0 0 0]

z =

1 0 3
4 0 6
7 0 9
-> increment can also be made by p=linspace(0,2*pi,50) so we can see increment
form 0 to 2pi with 50 parts
->to get identity matrix use z=eye(4,4) or z=eye(4)

z =

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
->to access specified elements of matrix use
z=eye(4)

z =

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

>> x=z(1,2:3)

x =

0 0
to get elements in column use
x=z(2:4,3) ( we get elements in 3 column 2 to 4 elements of row)

x =

0
1
0
-> to get determinent use det(z)
->to plot 2 graphs simultaneously with different color and frequency
the code is as follows
clc;
clear all;
fc1=10;
fc2=20;
t=0:0.001:0.5;
x=sin(2*pi*fc1*t);
y=sin(2*pi*fc2*t);
plot(t,x);
hold on;
plot(t,y,'r:');
in the above comand r is for color red,b for blue,g for green etc...
-- for dashed lines; : for dotted lines ; o for circles etc....
-> the below is the code to plot 4 subplots in the same window

clc;
clear all;
fc1=10;
fc2=20;
fc3=30;
fc4=40;
t=0:0.001:0.5;
x=sin(2*pi*fc1*t);
y=sin(2*pi*fc2*t);
z=sin(2*pi*fc3*t);
w=sin(2*pi*fc4*t);
subplot(2,2,1);
plot(t,x);
xlabel('time in sec');
ylabel('amplitude');
title('sine plot');
legend('fc1=10Hz');
%hold on;
subplot(2,2,2);
plot(t,y,'r:','LineWidth',2);
xlabel('time in sec');
ylabel('amplitude');
title('sine plot');
legend('fc2=20Hz');
subplot(2,2,3);
plot(t,z,'m--','LineWidth',3);
xlabel('time in sec');
ylabel('amplitude');
title('sine plot');
legend('fc3=30Hz');
subplot(2,2,4);
plot(t,w,'g-.');
xlabel('time in sec');
ylabel('amplitude');
title('sine plot');
legend('fc4=40Hz');

->code for creating magic matrix


m=magic(3)

m =

8 1 6
3 5 7
4 9 2
sum of row wise elements = sum of column wise elements=sum of diagonal elements

-> simple program to plot sinc function


t=linspace(-5,5);
y=sinc(t);
plot(y);

sinc FUNCTION
for creation of function in editor select new->function there the code is as
follows
function [ val ] = sinccal( fre,time )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
val=sinc(2*fre*time)

end
->PROGRAM FOR PLOTTING SINC FUNCTIONCS USING THE SINCCAL FUNCTION WE CREATED
w1=100;
w2=200;
w3=300;
t=linspace(-2,2);
x1=sinccal(w1,t);
x2=sinccal(w2,t);
x3=sinccal(w3,t);
plot(t,x1);
hold on;
plot(t,x2,'r');
plot(t,x3,'c');
xlabel('time');
ylabel('amplitude');
title('sincfunction');

Anda mungkin juga menyukai