matlab程序练习

  • 格式:doc
  • 大小:665.00 KB
  • 文档页数:6

hjl 笔记1.将存于E 盘根目录的图片按顺序运动 for i=1:3k=int2str(i);k1=strcat('e:\',k,'.jpg'); #读取存于E 盘根目录的后缀名为.jpg 的图片按顺序运动# a1=imread(k1); image(a1);m(:,i)=getframe; endmovie(m,10)2.随机生成一个6行10列矩阵,矩阵元素在0与1之间。

如果那个元素大于等于0.5,则把这个元素变为1;如果哪个元素小于0.5,则把这个元素变为0。

最后把结果显示出来 Ra=rand(6,10); R=Ra; for i=1:6for j=1:10if Ra(i,j)<0.5 Ra(i,j)=0; elseRa(i,j)=1; end end end R Ra3.使用程序绘制颜色渐变的图形 for j=1:30 for i=1:20 a(i,j)=j end endimage(a)510152025302468101214161820for i=1:20 for j=1:30 a(i,j)=i end endimage(a)510152025302468101214161820r=1;for t=0:0.01:2*pifor m=0:0.01:2*pix=r*cos(m)*cos(t); y=r*sin(m)*cos(t); z=r*sin(t); hl=plot3(x,y,z);set(hl,'color',[z,z,z]); end hold on; endlighting none-1-0.50.51-1-0.50.51-0.500.514.计算矩阵的最大值与均值。

> h=rand(6)/*随机产生矩阵*/h =0.9501 0.4565 0.9218 0.4103 0.1389 0.01530.2311 0.0185 0.7382 0.8936 0.2028 0.74680.6068 0.8214 0.1763 0.0579 0.1987 0.44510.4860 0.4447 0.4057 0.3529 0.6038 0.93180.8913 0.6154 0.9355 0.8132 0.2722 0.46600.7621 0.7919 0.9169 0.0099 0.1988 0.4186 >> [m,i]=max(h)m =0.9501 0.8214 0.9355 0.8936 0.6038 0.9318i =1 3 52 4 4>> [m1,j]=max(m)m1 =0.9501j =1最大值为0.9501,第1列,为第1行>> k=mean(h)k =0.6546 0.5247 0.6824 0.4230 0.2692 0.5039 >> kk=mean(k)kk =0.5096求出平均值为0.5096>> a=[1 2 3;2 3 4;3 4 5;4 5 6;5 6 7];>> size(a)ans =5 3>> a(5,2)ans =6A是数组,size(a)可以得到该数组是几维的,以及各个维数的大小,用a(i,j)可实现数组元素的调用动态I LOVE YOU[X,Y,Z] = meshgrid(linspace(-3,3,101));F = -X.^2.*Z.^3-(9/80).*Y.^2.*Z.^3+(X.^2+(9/4).*Y.^2+Z.^2-1).^3;hFigure = figure;sz = get(hFigure, 'Position');set(hFigure, 'Position', [sz(1)-0.15*sz(3) sz(2) 1.3*sz(3) sz(4)]);set(hFigure,'color','w', 'menu','none');hAxes = axes('Parent',hFigure,'NextPlot','add',...'DataAspectRatio',[1 1 1],...'XLim',[30 120],'YLim',[35 65],'ZLim',[30 75]);view([-39 30]);axis offhidden onp = patch(isosurface(F,-0.001));set(p,'FaceColor','w','EdgeColor','w');for iX = [35 38 41 45 48 51 54 57 61 64 67]plane = reshape(F(:,iX,:),101,101);cData = contourc(plane,[0 0]);xData = iX.*ones(1,cData(2,1));plot3(hAxes,xData,cData(2,2:end),cData(1,2:end),'k');pause(.1), drawnowendfor iY = [41 44 47 51 55 58 61]plane = reshape(F(iY,:,:),101,101);cData = contourc(plane,[0 0]);yData = iY.*ones(1,cData(2,1));plot3(hAxes,cData(2,2:end),yData,cData(1,2:end),'k');pause(.1), drawnowendfor iZ = [36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 69 71] plane = F(:,:,iZ);cData = contourc(plane,[0 0]);startIndex = 1;if size(cData,2) > (cData(2,1)+1)startIndex = cData(2,1)+2;zData = iZ.*ones(1,cData(2,1));plot3(hAxes,cData(1,2:(startIndex-1)),...cData(2,2:(startIndex-1)),zData,'k');endzData = iZ.*ones(1,cData(2,startIndex));plot3(hAxes,cData(1,(startIndex+1):end),...cData(2,(startIndex+1):end),zData,'k');pause(.1), drawnowendpause(.2)text(7,50,70,'I', 'fontWeight','bold','FontAngle','italic','fontsize',60) pause(.5)text(80,50,43,'you', 'fontWeight','bold','FontAngle','italic','fontsize',60) pause(.2)line([20 80],[50 50],[52.5 52.5], 'color','w')line([50 50],[20 80],[52.5 52.5], 'color','w')line([50 50],[50 50],[30 80], 'color','w')>> B=imread('d:\117.jpg');B2=rgb2hsv(B);B11=B2(:,:,1);B12=B2(:,:,2);B13=B2(:,:,3);subplot(1,4,1);imshow(B)subplot(1,4,2);imshow(B11)subplot(1,4,3);imshow(B12)subplot(1,4,4);imshow(B13)>> B=imread('d:\117.jpg');>> imshow(B)Warning: Image is too big to fit on screen; displaying at 42% scale. > In truesize>Resize1 at 308In truesize at 44In imshow at 161>> B=imread('d:\117.jpg');B1=imresize(B,0.15);B11=B1(:,:,1);B12=B2(:,:,2);B13=B1(:,:,3);subplot(1,3,1);imshow(B11) subplot(1,3,2);imshow(B12) subplot(1,3,3);imshow(B13)。