您好,欢迎访问三七文档
当前位置:首页 > 中学教育 > 初中教育 > 6---matlab---对矩阵中元素的操作
对矩阵中元素的操作:删除某一行:clcclearalla=[123;456]a(:,3)=[];a结果:a=123456a=1245添加一行元素:clcclearalla=[123;456]a(3,:)=[789]结果:a=123456a=123456789程序三:clcclearalla=ones(2,3)b=zeros(1,2)c=eye(2)d=diag(1:3)e=diag([123;456])f=rand(2,3)g=randn(2,3)g1=tril(g)g2=triu(g)结果:a=111111b=00c=1001d=100020003e=15f=0.81470.12700.63240.90580.91340.0975g=-0.43363.5784-1.34990.34262.76943.0349g1=-0.4336000.34262.76940g2=-0.43363.5784-1.349902.76943.0349程序四:在(30,50)之间的随机分布的五阶矩阵:程序:a=rand(5)b=30.*a+20结果:a=0.31710.76550.64630.65510.34040.95020.79520.70940.16260.58530.03440.18690.75470.11900.22380.43870.48980.27600.49840.75130.38160.44560.67970.95970.2551b=29.513042.965539.389439.652930.211648.506743.856041.280924.878437.558021.033425.606242.640623.569926.714433.162334.692928.280834.950942.538031.446833.367640.391148.792327.6529矩阵旋转:程序clcclearalla=[1:3;4:6];a1=fliplr(a)a2=flipud(a)a3=rot90(a)a4=rot90(a,2)结果:a=123456a1=321654a2=456123a3=362514a4=654321矩阵元素的重新排列:Reshape(a,m,n)按列方向从新排列元素:clcclearalla=[1:3;4:6]a1=reshape(a,3,2)结果:a=123456a1=154326查看矩阵大小:clcclearalla=[1:3;4:6];a1=reshape(a,3,2);b1=size(a)b11=size(a,1)b12=size(a,2)b2=size(a1)b21=size(a1,1)b21=size(a1,2)结果:b1=23b11=2b12=3b2=32b21=3b21=2求矩阵的行数和列数,并得出两者中的最大值:clcclearalla=[1:3;4:6];b=reshape(a,1,6)a1=max(size(a))a2=length(a)b1=length(b)结果:b=142536a1=3a2=3b1=6任意两个矩阵的kronecker乘积-----------------张量积A是m,n维数。。b是l,t维数程序:clcclearalla=[12;34;56]b=diag(1:4)c=kron(a,b)a1=size(a)b1=size(b)c1=size(c)结果:a=123456b=1000020000300004c=100020000200040000300060000400083000400006000800009000120000120001650006000010000120000150001800002000024a1=32b1=44c1=128C行数=a行数乘以b行数,,,列数=a列数乘以b列数函数在矩阵上取值:clcclearallx=[0:pi/4:pi];a=[1:3;4:6];y1=sin(x)y2=exp(a)y3=sqrt(a)结果:y1=00.70711.00000.70710.0000y2=2.71837.389120.085554.5982148.4132403.4288y3=1.00001.41421.73212.00002.23612.4495
本文标题:6---matlab---对矩阵中元素的操作
链接地址:https://www.777doc.com/doc-3825328 .html