《matlab实验2MATLAB基础知识.docx》由会员分享,可在线阅读,更多相关《matlab实验2MATLAB基础知识.docx(7页珍藏版)》请在优知文库上搜索。
1、试验2MATLAB基础学问一、试验目的1 .熟识MATLAB的数据类型2 .熟识MATLAB的基本矩阵操作3 .熟识MATLAB的运算符4 .熟识MATLAB的字符串处理二、试验内容1 .创建结构体DataTyPeS,属性包含MATLAB支持的全部数据类型,并通过赋值构造结构体二维数组。DataTypes.char=char(65);DataTypes.string=hello,;DataTypesjnt=100;DataTypes.single=1.560DataTypes=char:,Astring:,hello,int:100single:1.5600DataTypes(2).char=
2、char(66);DataTypes(2).string=kugou,;DataTypes(2).int=200;DataTypes(2).single=3.14DataTypes=1x2structarraywithfields:charstringintsingle2 .用满矩阵和稀疏矩阵存储方式分别构造下述矩阵。飞100O10000A=0010000010答:A =1OOOB =OOOOA =OOOOA =O1OOA =O1OOA =O1OOOO1OOO1OOO1OOO1OOO1OOO1OOO1OOO1OOO11OO1OOO1OOO11OOOOOO1OS=sparse(l,2,3,4,2
3、,1,3,4,1,1,1,1,4,5);D=full(D)D=010001000000100000103.在矩阵A末尾增加一行(元素全为1)得到矩阵B,删除矩阵A的最终一列得到矩阵C,替换矩阵A的全部非零元素为2得到矩阵D。分别查看矩阵(A,B,C,D)的长度。答:A=eye(4)B=zeros(4,l)A(M)=OA(2,l)=lA(l,2)=lA(2,2)=0C=ABA=1000010000100001B=0000A=00000100OOA=OO11OOOOA=O111OOOOA=O11OOOOOC=O11OOOOOA=CA=O11OOOOOB=11O1OOOO1OO1OOOO1OO1OO
4、OO1OO1OOOOOO1OOO1OOOOOOO1OOO1O111O1OO11OOO1OO1O1OOO11OOOO1C=O1OO1OOOOO1OOOO1Aones(4,5)ans=1O111O111111O1111D=ans+ones(4,5)1O1D=21222122222212222212a=size(八)b=size(B)c=size(C)d=size(D)a=44d=454 .给定矩阵E=rand(4,4)晨计算C+E,C.*E和CE三E=rand(4,4)E=0.95010.89130.82140.92180.23110.76210.44470.73820.60680.45650.6
5、1540.17630.48600.01850.79190.4057C+Eans=0.95011.89130.82140.92181.23110.76210.44470.73820.60680.45651.61540.17630.48600.01850.79191.4057C.*Eans=00.8913000.2311000000.615400000.4057CEans=0.23110.76210.44470.73820.95010.89130.82140.92180.60680.45650.61540.17630.48600.01850.79190.40575 .将10进制的80转换为二进制的字符串,并从中查找0的个数。答:dec2bin(80)ans=s=,1O1OOOO,n=strfind(s,O)s=n=24567length(n)ans=5