You are on page 1of 11

qwertyuiopasdfghjklzxcvbnmqwe

nmqwertyui rtyuiopasdfghjklzxcvb
opasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfgh
MATLAB
PROGRAMMING IN MATLAB
jklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqw
ertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiop
asdfghjklzxcvbnmqwertyuiopasdf
xcvbnmqwertyuiopasdfghjk ghjklz
lzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqw
ertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmrtyuiopasdf
2semester exam\2/5/2013

Q2 Given a color indexed image X[600,600] ,write a MATLAB program


to:
1:-Read the indexed image X.
2:-Convert the indexed image X to RGB image Y[600,600]
3:-creat another image (Z[600,600]) consist of( ) four quarters, the
first quarter is taken from the resized Y-image , the second quarter is
taken from Y-image but with RED color only , the third quarter is taken
from Y-image but with GREEN color only , the four quarter is taken from
Y-image but with BLUE color only.
4:-show the image (Z),then save the image (Z) in the partition E:

Solution
[x,map]=imread('trees.tif');
i=ind2rgb(x,map);
j=imresize(i,.5);
[x,s,z]=size(j)
z(1:x,1:s,1:z)=j(1:x,1:s,1:z);
z(1:x,s+1:s*2,1)=j(1:x,1:s,1);
z(x+1:x*2,1:s,2)=j(1:x,1:s,2);
z(x+1:x*2,s+1:s*2,3)=j(1:x,1:s,3);
imshow(z)
imwrite(z,'E:\z-new.png')
Final exam 7/6/2012

Q3/A: for the shape shown in figure below, write a MATLAB program to:
1.plot the curve y=f(x) for x varying from 0 to .
2.evaluate the area under curve using numerical solua on.

solution
clear;clc;
x=0:pi/60:pi
y=10*sin(x)
for i=1:length(x)
if x(i)<=pi/6
y(i)=5;
else if(x(i)>=5*pi/6)
y(i)=5;
end
end
end
plot(x,y)
axis([0,pi,0,10])
xlabel('x')
ylabel('y')
Area=trapz(x,y)
2semester exam\2/5/2013
Q1:)B:Write a MATLAB program to compress and
expand a snail

solution
clear;clc;
axis tight
a=0:pi/60:25*pi;
w=2*pi/15;
m=moviein(16)
for t=1:16
x=exp(-a/50).*sin(a);
y=exp(-a/50).*cos(a);
z=(1+cos(w.*(t))).*a;
plot3(x,y,z)
m(:,t)=getframe;
pause(.1)
end
movie(m,5)
Make-up Exam\11/9/2012

Q4) a:- Given a RGB color image(X) having the size[500,500],write a


MATLAB program to:-
1:-Read the a RGB color image(X) .
2:- Creat and show a new image (Y) which has the size [500,500] include
the image X with a BLACK corner.

Note:-the black square is [50,50]

solution
clear;clc;
y=imread('x.png')
y(1:50,1:50,:)=0;
y(1:50,450:500,:)=0;
y(450:500,1:50,:)=0;
y(450:500,450:500,:)=0;
imshow(y)

2semester exam\24/4/2012

B: Write a MATLAB program to generate a


snail( ) shon in g.2

solution
clear;clc;
z=0:pi/20:12*pi
x=exp(-z/20).*sin(z)
y=exp(-z/20).*cos(z)
plot3(x,y,z)
2semester exam\24/4/2012
Q2:)Given two RGB images (X & Y) having the same size [300,300],
Write a MATLAB program to:-
1:- Creat( ) and show a new image (Z) which has the elements of
upper main diagonal taken from X-image ,and the lower elements taken
from Y-image.
2:- Creat another image(V) consists of( ) two parts ,the first part is
taken from X-image, and the second part is taken from Y-image as
shown in g.1, nally save the image (V) in the partition E:

solution
clear;clc;
x=imread('x.png');
y=imread('y.png');
for k=1:3
z1(:,:,k)=triu(x(:,:,k));
z2(:,:,k)=tril(y(:,:,k));
end
z=z1+z2
imshow(z)
-------------------------------------------------------------------
clear;clc;
x=imread('x.jpg');
y=imread('y.png');
for i=1:300
for j=1:300
for k=1:3
if i<=150
v(i,j,k)=x(i,j,k);
else
v(i,j,k)=y(i,j,k);
end; end;end;end
imshow(v)
imwrite(v,'E:\v-new.png')

x=imread('x.png');
y=imread('y.png');
v(1:150,:,1:3)=x(1:150,:,1:3)
v(151:300,:,1:3)=y(151:300,:,1:3)
imshow(v)

clear;clc;
[x,y,z]=sphere;
surf(3*x,4*y,4*z);
axis tight
set(gca,'nextplot','replacechildren');
for i=1:20
surf(x,y,z)
set(gca,'nextplot','add');
surf(3*sin(2*pi*i/10)+x,4*cos(2*pi*i/10)+y,z)
f(i)=getframe;
set(gca,'nextplot','replacechildren');
pause(.1)
end
movie(f,5)

Quize:-write a MATLAB programe to plot a white dot the distance


between each dot and another is 10 pixel.

soulution
clear;clc;
r=imread('football.jpg')
[x,y,z]=size(r)
r(1:10:x,1:10:y,:)=200
imshow(r)

soulution using for loop


clear;clc;
r=imread('football.jpg');
[x,y,z]=size(r)
for i=1:10:x
for j=1:10:y
for k=1:z
r(i,j,k)=200;
end
end
end
imshow(r)
Example:-For the RLC circuit shown in figure,if the transfer function
as

)
( )= =
)

If L=5H and C=1.12µF,plot the frequency response for (w) varied


from 1rad/sec to 10 krad/sec when
a)R1=10000 b)R2=100

solution
clear;clc;
l=5;
c=1.12e-6;
r1=10000;
r2=100;
num1=[r1/l,0]
den1=[1,r1/l,1/(l*c)]
w=logspace(log10(1),log10(10000))
h1=freqs(num1,den1,w)
f=w/(2*pi);
mag1=abs(h1);
phase1=angle(h1)*180/pi;
num2=[r2/l,0]
den2=[1,r2/l,1/(l*c)]
h2=freqs(num2,den2,w)
mag2=abs(h2);
phase2=angle(h2)*180/pi;
% plot the responce
subplot(221), loglog(f,mag1,'.r')
title('magnitude responce R=10K')
ylabel('magnitude')
subplot(222), loglog(f,mag1,'b')
title('magnitude responce R=.1K')
ylabel('magnitude')
subplot(223), semilogx(f,phase1,'.r')
title('phase responce R=10K')
xlabel('Frequency,Hz'),ylabel('angle in degrees')
subplot(224), semilogx(f,phase2,'b')
title('phase responce R=.1K')
xlabel('Frequency,Hz'),ylabel('angle in degrees')

clc;clear;

r=imread('peppers.png');

y(51:350,51:350,:)=r(1:300,1:300,:);

y(1:50,1:400,1)=255;

y(1:400,1:50,1)=255;

y(351:400,1:400,1)=255;

y(1:400,351:400,1)=255;

z(51:450,51:450,:)=y(1:400,1:400,:);

z(1:50,1:400,:)=0;

z(1:500,451:500,:)=0;

z(451:500,1:500,:)=0;

z(1:500,1:50,:)=0;
imwrite(y,'v.png')

imwrite(z,'z.png')

imshow(z)

You might also like