matlab简单运算

1,请创建一个3*3的矩阵,然后利用矩阵编辑器将其扩充为4*5矩阵;
 a=[1,2,3;4,5,6;7,8,9]

a =

     1     2     3
     4     5     6
     7     8     9
 b=eye(4,5)

b =

     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
     0     0     0     1     0

>> b(2:4,2:4)=a

b =

     1     0     0     0     0
     0     1     2     3     0
     0     4     5     6     0
     0     7     8     9     0
2,请创建一个等比矩阵,然后由它产生一个对角阵,并储存这个矩阵;
x=100;n=floor(log2(x));an=2.^(1:n)

an =

     2     4     8    16    32    64

>> bn=diag(an)

bn =

     2     0     0     0     0     0
     0     4     0     0     0     0
     0     0     8     0     0     0
     0     0     0    16     0     0
     0     0     0     0    32     0
     0     0     0     0     0    64
save('util.mat','bn')
3,调出上面储存的矩阵,并由它产生一个列向量
bn =

     2     0     0     0     0     0
     0     4     0     0     0     0
     0     0     8     0     0     0
     0     0     0    16     0     0
     0     0     0     0    32     0
     0     0     0     0     0    64
b=bn(:)%

b =

     2
     0
     0
     0
     0
     0
     0
     4
     0
     0
     0
     0
     0
     0
     8
     0
     0
     0
     0
     0
     0
    16
     0
     0
     0
     0
     0
     0
    32
     0
     0
     0
     0
     0
     0
    64


你可能感兴趣的:(matlab简单运算)