资源预览内容
第1页 / 共11页
第2页 / 共11页
第3页 / 共11页
第4页 / 共11页
第5页 / 共11页
第6页 / 共11页
第7页 / 共11页
第8页 / 共11页
第9页 / 共11页
第10页 / 共11页
亲,该文档总共11页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
实验6 Matlab绘图一、实验目的1、掌握绘制二维图形的常用函数。2、掌握绘制三维图形的常用函数。3、掌握图像读写函数和显示函数的使用方法。二、实验内容1、已知,完成以下操作:(1)在同一坐标系下,用不同的颜色和线型绘制三条曲线。(2)在同一个图形窗口中,以子图的形式绘制三条曲线。(3)在同一个图形窗口中,以子图的形式,分别用条形图、阶梯图、杆图和填充图绘制三条曲线。解答:(1)x=-10:0.001:10;y1=x.2;y2=cos(2*x);y3=y1.*y2;plot(x,y1,x,y2,x,y3)(2) x=-10:0.001:10;y1=x.2;y2=cos(2*x);y3=y1.*y2;subplot(1,3,1);plot(x,y1);subplot(1,3,2);plot(x,y2);subplot(1,3,3);plot(x,y3);(3)x=-10:0.01:10;y1=x.2;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1);bar3(x,y1);hold onbar3(x,y2);hold onbar3(x,y3);hold onview(90,0);subplot(2,2,2);stairs(x,y1);hold onstairs(x,y2);hold onstairs(x,y3);hold onsubplot(2,2,3);stem(x,y1); hold onstem(x,y2);hold onstem(x,y3);hold onsubplot(2,2,4); fill(x,y1,x,y2,x,y3); 2、设绘制 和曲线,并给图形添加图形标注(title(绘图曲线),xlabel(x轴), ylabel (y 轴),text(在合适位置标注两曲线名),legend(y1,y2),axis(指定范围),显示网格,不显示边框)。解答:x=0:0.001:2*pi;y1=0.5*log(x+sin(pi*x);y2=(0.5+3*sin(x)./(1+x.2).*cos(x);plot(x,y1,x,y2)title(绘图曲线);xlabel(x轴);ylabel(y轴);text(x(2000),y1(2000),leftarrow y1)text(x(2000),y2(2000),leftarrow y2)legend(y1,y2);axis(0 2*pi -inf inf);grid on;box off;3、绘制曲面图形,在同一窗口不同子图上分别采用faceted,flat,interp进行着色处理。 解答:S=linspace(0,0.5*pi,100);T=linspace(0,1.5*pi,100);s,t=meshgrid(S,T);x=cos(s).*cos(t);y=cos(s).*sin(t);z=sin(s);surf(x,y,z);shading facetedfacetedflatinterp4、绘制函数的曲面图和等高线。 其中的21个值均匀分布在-5,5范围,的31个值均匀分布在0,10,要求使用subplot(1,2,1)和subplot(1,2,2)将生产的曲面图和等高线图画在同一窗口上。绘制曲面时采用hot(5)色图,标注标题(曲面图),标注各个坐标轴,观察角度为(-20,20)。等高线图标注标题(等高线图),标注各个坐标轴,观察角度为(0,90)。解答:X=linspace(-5,5,21);Y=linspace(0,10,31);x,y=meshgrid(X,Y);z=5*cos(x).*cos(y).*exp(-sqrt(x.2+y.2)/4);subplot(1,2,1);surf(x,y,z);colormap(hot(5);title(曲面图);xlabel(x轴);ylabel(y轴);zlabel(z轴);view(-20,20);subplot(1,2,2);contour3(x,y,z);title(等高线图);xlabel(x轴);ylabel(y轴);zlabel(z轴);view(0,90);5、假设的21个值均匀分布在-5,5范围,的31个值均匀分布在0,10,曲面方程满足: (1)绘制函数的曲面图,并且将它绕z轴旋转。(2)绘制函数的曲面图,采用imwrite函数将绘制的曲面保存在c:目录下,文件名为tu1.jpg。采用saveas函数将绘制的曲面保存在c:目录下,文件名为tu1.bmp。检查c:目录是否存在这两个文件。(3)采用imread函数读取tu1.jpg并分别在同一窗口不同子窗口用 image函数、 imshow显示tu1.jpg图像。解答:(1) X=linspace(-5,5,21);Y=linspace(0,10,31);x,y=meshgrid(X,Y);z=cos(x).*cos(y).*exp(-sqrt(x.2+y.2)/4);surf(x,y,z)view(150,0);(2)X=linspace(-5,5,21);Y=linspace(0,10,31);x,y=meshgrid(X,Y);z=cos(x).*cos(y).*exp(-sqrt(x.2+y.2)/4);surf(x,y,z)view(150,0);data,map=getframe;imwrite(data,c:tu1.jpg,jpg); 使用MATLAB2012b,出现下面问题,改存在系统默认目录中Error using imwrite (line 459)Unable to open file c:tu1.jpg for writing. You may not have write permission.Error in f (line 8)imwrite(data,c:tu1.jpg,jpg);info=imfinfo(tu1.jpg)info = Filename: G:Program Filesmatlab2012bR2012bbintu1.jpg FileModDate: 21-Apr-2013 14:55:45 FileSize: 31215 Format: jpg FormatVersion: Width: 435 Height: 343 BitDepth: 24 ColorType: truecolor FormatSignature: NumberOfSamples: 3 CodingMethod: Huffman CodingProcess: Sequential Comment: saveas(gcf,tu1.bmp,bmp)imfinfo(tu1.bmp)ans = Filename: G:designmatlabtu1.bmp FileModDate: 21-Apr-2013 15:11:36 FileSize: 236278 Format: bmp FormatVersion: Version 3 (Microsoft Windows 3.x) Width: 560 Height: 420 BitDepth: 8 ColorType: indexed FormatSignature: BM NumColormapEntries: 256 Colormap: 256x3 double RedMask: GreenMask: BlueMask: ImageDataOffset: 1078 BitmapHeaderSize: 40 NumPlanes: 1 CompressionType: none BitmapSize: 235200 HorzResolution: 0 VertResolution: 0 NumColorsUsed: 0 NumImportantColors: 0(3)cdata=imread(tu1.jpg);subplot(1,2,1);image(cdata);subplot(1,2,2);imshow(cdata);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号