# matlab学习笔记之基础知识（一）

1.元胞数组

1）直接赋值

>> a={'matlab',20;ones(2,3),1:10}

a =

'matlab'        [         20]
[2x3 double]    [1x10 double]

2）通过cell函数创建

>> b = cell(2,2);
b{1,1} = 'matlab';
b{1,2} = 20;
b{2,1} = ones(2,3);
b{2,2} = 1:10;
>> b

b =

'matlab'        [         20]
[2x3 double]    [1x10 double]

2.结构体

1）直接赋值

>> A.b1 = 111;

>> A.b2 = ones(3);

>> A.b3 = 'Matlab 2013a';

>> A

A =

b1: 111

b2: [3x3 double]

b3: 'Matlab 2013a'

2）通过struct函数创建

>> B = struct('b1',222,'b2',ones(3),'b3','hello');

>> B

B =

b1: 222

b2: [3x3 double]

b3: 'hello'

1.方程的解

（1）       求逆运算    x = inv(A) * B

（2）       左除运算    x = A\B

>> A = [6,3,4;-2,5,7;8,-1,-3];
>> B = [3;-4;-7];
>> x = inv(A)*B;
>> x
x =

1.0200

-14.0000

9.7200

>> y = A\B;
>> y
y =

1.0200

-14.0000

9.7200

2.矩阵的秩

R = rank(A)

>> r = rank(A);
>> r
r =

3

3.矩阵的特征值与特征向量

[v, lambda] = eig(A)

>> [v, lambda] = eig(A)

v =

0.8013   -0.1094   -0.1606

0.3638   -0.6564    0.8669

0.4749    0.7464   -0.4719

lambda =

9.7326         0         0

0   -3.2928         0

0         0    1.5602

4.矩阵的乘幂与开方

>> A1 = A ^2;                     %乘幂

>> A2 = sqrt(A);                 %开方

>> A1

A1 =

62    29    33

34    12     6

26    22    34

>> A2

A2 =

2.4495 + 0.0000i   1.7321 + 0.0000i   2.0000 + 0.0000i

0.0000 + 1.4142i   2.2361 + 0.0000i   2.6458 + 0.0000i

2.8284 + 0.0000i   0.0000 + 1.0000i   0.0000 + 1.7321i

5.矩阵的指数与对数

>> y1 = exp(A);          %指数

>> y2 = log(A);           %对数

>> y1

y1 =

1.0e+03 *

0.4034    0.0201    0.0546

0.0001    0.1484    1.0966

2.9810    0.0004    0.0000

>> y2

y2 =

1.7918 + 0.0000i   1.0986 + 0.0000i   1.3863 + 0.0000i

0.6931 + 3.1416i   1.6094 + 0.0000i   1.9459 + 0.0000i

2.0794 + 0.0000i   0.0000 + 3.1416i   1.0986 + 3.1416i

6.矩阵的提取与翻转

>> A_triu = triu(A)

A_triu =

6     3     4

0     5     7

0     0    -3

>> A_tril = tril(A)

A_tril =

6     0     0

-2     5     0

8    -1    -3

>> A_diag = diag(A)

A_diag =

6

5

-3

>> A_ud = flipud(A)

A_ud =

8    -1    -3

-2     5     7

6     3     4

>> A_lr = fliplr(A)

A_lr =

4     3     6

7     5    -2

-3    -1     8

>> A_l = flipdim(A,1)

A_l =

8    -1    -3

-2     5     7

6     3     4

>> A_h = flipdim(A,2)

A_h =

4     3     6

7     5    -2

-3    -1     8

>> A_r90 = rot90(A)

A_r90 =

4     7    -3

3     5    -1

6    -2     8

7.“商”及“余”多项式

[q, r] = deconv(p1, p2)，p1为输入分子多项式系数，p2为输入分母多项式系数，q为输出多项式的“商”，r为输出多项式的“余”。

>> p1 = conv([1,0,1],conv([1,3],[1,1]))

p1 =

1     4     4     4     3

>> p2 = [1,2,1]

p2 =

1     2     1

>> [q,r] = deconv(p1,p2)

q =

1     2    -1

r =

0     0     0     4     4

未完待续。。。

posted @ 2016-07-07 15:50  Acelit  阅读(690)  评论(0编辑  收藏  举报