杭州电子科技大学matlab课内实验

第一次试验

1.画出公式y=cos(x)*(5=8*sin(x))+x*e –x 分别画在0-2x内取1000个的曲线图,和x=【-3,3】取0.01间隔的曲线图

x1=linspace(0,2*pi,100);

y1=cos(x1).*(5+8*sin(x1))+x1.*exp(-x1); subplot(2,1,1); plot(x1,y1); x2=-3:0.01:3;

y2=cos(x2).*(5+8*sin(x2))+x2.*exp(-x2); subplot(2,1,2); plot(x2,y2)

2.画出公式x=cos(t+a),y=sin(2t),其中a=0,π/6,π/3,π/2,在4个子图中画出曲线

t=-10:0.001:10; c1=0;

x1=cos(t+c1); y1=sin(2*t); subplot(2,2,1); plot(x1,y1); c2=pi/6;

x2=cos(t+c2); y2=sin(2*t); subplot(2,2,2); plot(x2,y2); c3=pi/3;

x3=cos(t+c3); y3=sin(2*t); subplot(2,2,3); plot(x3,y3); c4=pi/2;

x4=cos(t+c4); y4=sin(2*t); subplot(2,2,4); plot(x4,y4)

3.读取一幅彩色图像,将其转变成灰度图像,将灰度图顺时针旋转90,将该图吧噢存到硬盘上

i=imread('C:\\Documents and Settings\\Administrator\\桌面\\dddd.bmp'); a=double(i); pr=a(:,:,1); pg=a(:,:,2); pb=a(:,:,3);

a1=(pr+pg+pb)/3; x=size(a1);

t=zeros(x(2),x(1));

for i=1:x(1)

t(:,x(1)-i+1)=a1(i,:)'; end

figure;imshow(uint8(t));

imwrite(uint8(t),'C:\\Documents and Settings\\Administrator\\桌面\\dddd2.bmp'); 4.读取一幅图像,并显示图像,在图像上用鼠标取两个点,并在图上用*号显示这两个点,以这两个点为左上角和右下角在图上画一个矩形框,截取该矩形框内的子图像,显示并保存在硬盘上

i=imread('\\\\psf\\Home\\Desktop\\ddd2.bmp'); figure;

imshow(i); hold on;

[x,y]=ginput(2); for m=1:2

plot(x(m),y(m),'*'); end

n=imcrop(i,[min(x(1),x(2)),min(y(1),y(2)),abs(x(1)-x(2)),abs(y(1)-y(2))]); figure;

imshow(n);

imwrite(n,'\\\\psf\\Home\\Desktop\\ddd3.bmp');

第二次试验

1.鼠标点击空白图面,实时显示鼠标点和轨迹 functiondsa

figure('WindowButtonDownFcn',@md);

axes('XLimMode','manual','yLimMode','manual'); hold on;

function md(src,eventdata) ud=get(src,'userdata'); cp=get(gca,'currentpoint'); x=cp(1,1);y=cp(1,2); plot(x,y,'r*'); if ~isempty(ud)

line([ud(1),x],[ud(2),y]); end

set(src,'userdata',[x,y]); 2.音乐柱状图的动态标识 fori=1:1000 pause(0.3); y=rand(1,10); bar(y); end

3.编写一个函数,以图像文件路径为输入参数 (1)显示灰度图像

(2)图像灰度值通过y=x2变换并拉伸到【0,255】;

(3)图像分为上下左右四个字块,并显示这四个子块图像;

(4)把左上子块和右下子块图像进行交换,把右上和左下进行交换,并显示交换后的图像 w=imread('C:\\Documents and Settings\\Administrator\\桌面\\图片.bmp'); figure(1); b=rgb2gray(w); figure(1);

imshow(uint8(b));title('灰度图'); c=b.*b; figure(2);

imshow(uint8(c));title('改变灰度图'); [hang lie]=size(b); figure(3); title('分割灰度图'); subplot(2,2,1);

imshow(uint8(b(1:hang/2,1:lie/2))); subplot(2,2,2);

imshow(uint8(b(1:hang/2,lie/2:lie))); subplot(2,2,3);

imshow(uint8(b(hang/2:hang,1:lie/2))); subplot(2,2,4);

imshow(uint8(b(hang/2:hang,lie/2:lie))); figure(4);

title('交换分割灰度图'); subplot(2,2,4);

imshow(uint8(b(1:hang/2,1:lie/2))); subplot(2,2,3);

imshow(uint8(b(1:hang/2,lie/2:lie))); subplot(2,2,2);

imshow(uint8(b(hang/2:hang,1:lie/2))); subplot(2,2,1);

imshow(uint8(b(hang/2:hang,lie/2:lie)));

第三次试验

制作一个GUI,实现简易计算器

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4