0% found this document useful (0 votes)
62 views

Laboratorysessi Onno.02: Geti Ntroducedwi Ththem Software

This document describes a MATLAB laboratory session on signals and systems. The objective was to get introduced to the MATLAB software. By the end of the lab, students should be able to develop basic programs pertaining to solving equations, manipulate matrices, use plotting tools in MATLAB, implement loops, and develop user-defined functions. Examples are provided to demonstrate the use of while and for loops in MATLAB to find odd numbers within a range and to calculate the factorial of a user-entered number.

Uploaded by

Adina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Laboratorysessi Onno.02: Geti Ntroducedwi Ththem Software

This document describes a MATLAB laboratory session on signals and systems. The objective was to get introduced to the MATLAB software. By the end of the lab, students should be able to develop basic programs pertaining to solving equations, manipulate matrices, use plotting tools in MATLAB, implement loops, and develop user-defined functions. Examples are provided to demonstrate the use of while and for loops in MATLAB to find odd numbers within a range and to calculate the factorial of a user-entered number.

Uploaded by

Adina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Labor

ator
ySessi
on#02 Si
gnal
s&Sy
stems(
EE-
231)
Depar
tmentofEl
ect
ri
cal
Engi
neer
ing NEDUni
ver
sit
yofEngi
neer
ingandTechnol
ogy

Labor
ator
ySes
sionNo.
02

Obj
ect
ive:

Geti
ntr
oducedwi
tht
heMATLABsof
twar
e.

Out
comes:

Byt
heendoft
hisl
ab,st
udentshoul
dbeabl
eto

a)Developbasicprogramsper t
aini
ngtosol
uti
onofequat
ions
b)ManipulateMatrices
c)Usevariousfeat
ur esofpl
ottingt
ool
sinMATLAB
d)Implementloops
e)Developuserdefinedfuncti
ons

I
mpl
eme
ntl
oops

S
tat
eme
nt:

I
mpl
eme
ntpr
ogr
amsi
nor
dert
ode
mons
tra
tet
heus
eofl
oops
tat
eme
ntsi
nma
tla
b.

 whi
lel
oop

Gi
venbel
owisaprog
ramt
ofi
ndoddnumbe
rsf
rom1t
othenumbe
rent
ere
dbyt
heus
erby
us
ingwhi
lel
oop.

i
=1;

f
pri
ntf
('
\n'
); %onel
i
nespace

di
sp(
'"
Displ
ayi
ngoddnumber
sfr
om 1t
oent
erednumber
"'
);

f
pri
ntf
('
\n'
);

n=i
nput
('
Ent
erano:
');%t
aki
ngi
nputf
rom user
Labor
ator
ySessi
on#02 Si
gnal
s&Sy
stems(
EE-
231)
Depar
tmentofEl
ect
ri
cal
Engi
neer
ing NEDUni
ver
sit
yofEngi
neer
ingandTechnol
ogy

whi
l
ei<=n

b=mod(
i,
2); %cal
cul
ati
ngmodul
us

i
fb~=0

di
sp(
i)
;

end

i
=i+1; %i
ncr
ement
ingi

end

Out
put
:

"
Displ
ayi
ngoddnumber
sfr
om 1t
oent
erednumber
"

Ent
erano:
6

 f
orl
oop

Fol
lowi
ngi
sapr
ogr
amt
ofi
ndf
act
ori
aloft
henumbe
rent
ere
dbyt
heus
erbyus
ingf
orl
oop.
Labor
ator
ySessi
on#02 Si
gnal
s&Sy
stems(
EE-
231)
Depar
tmentofEl
ect
ri
cal
Engi
neer
ing NEDUni
ver
sit
yofEngi
neer
ingandTechnol
ogy

f
pri
ntf
('
\n'
); %onel
i
nespace

di
sp(
' “
CALCULATI
NGFACTORI
AL” '
);

f
pri
ntf
('
\n'
);

n=i
nput
('
Ent
ert
henumber
:'
);%t
aki
ngi
nputf
rom usert
ofi
ndi
ts

f
act
ori
al

i
fn<0 %i
fno.i
slesst heni
han0t t’
swr
ongi
nput

di
sp(
'Wr
ongI
nput
')

el
se

f
=1;

f
ori
=1:
n %v
alueofi
rangesf
rom 1t
oent
eredno.

f
=f*
i;

end

di
sp(
'Fact
ori
ali
s:'
)

di
sp(
f) %di
spl
ayi
ngf
act
ori
alonscr
een

end
Labor
ator
ySessi
on#02 Si
gnal
s&Sy
stems(
EE-
231)
Depar
tmentofEl
ect
ri
cal
Engi
neer
ing NEDUni
ver
sit
yofEngi
neer
ingandTechnol
ogy

Out
put
:


CALCULATI
NGFACTORI
AL”

Ent
ert
henumber
:9

Fact
ori
ali
s:

362880

Out
come
:

Thef
oll
owinga
cti
vit
yma
deusunde
rst
andt
heus
eful
nes
sandi
mpl
eme
nta
tionofl
oops
tat
eme
nts
i
nma t
lab.
Labor
ator
ySessi
on#02 Si
gnal
s&Sy
stems(
EE-
231)
Depar
tmentofEl
ect
ri
cal
Engi
neer
ing NEDUni
ver
sit
yofEngi
neer
ingandTechnol
ogy

Fi
gur
e2020:
Giv
emeat
it
le

%%Ver
yBasi
cPr
ogr
am

cl
earal
l

f
lag=1;

whi
l
efl
ag==1

cl
c;

x=i
nput
('
Ent
eranar
ray:
'
,'s'
);

x=st
r2num(
x);
Labor
ator
ySessi
on#02 Si
gnal
s&Sy
stems(
EE-
231)
Depar
tmentofEl
ect
ri
cal
Engi
neer
ing NEDUni
ver
sit
yofEngi
neer
ingandTechnol
ogy

x_
mag=magni
(x)
;

x_
mean=av
rg_
1(x)
;

choi
ce=i
nput
('
Press1f
ormean,
2formag\
r:'
,
's'
);

choi
ce=st
r2num(
choi
ce)
;

swi
tchchoi
ce

case1

di
sp(
x_mean)
;

case2

di
sp(
x_mag)
;

ot
her
wise

di
sp(
'I
tseemsy
ouqui
t'
)

br
eak;

end

f=i
nput
('
Doy
ouwantt
ocont
inue?[
Y/N]'
,'
s'
);

i
ff=='
Y'|
f=='
y'

f
lag=1;

el
se

f
lag=0;

end

end

Code03:
Condi
ti
onsandl
oopsusi
ngMATLAB

You might also like