matlab-变量类型-数组-矩阵

1 变量类型

1.1基本

 1.2 特殊变量

  1. ans
  2. •i,j: complex number
  3. •Inf: 无穷大
  4. •eps: 2.2204e-016
  5. •NaN: not a number
  6. •pi:pai

 

注意:关键字是可以做变量的

1.3 numeric display format

1.4 some useful functions

  1. •clc: clear command windowdisplay
  2. •clear: remove all variables in the workspace
  3. •who: variables in the workspace
  4. •whos: variable information of the workspace

2 数组

1.1 定义

row vector:
>> a = [1 2 3 4]
column vector:
>> b= [1; 2; 3; 4]

1.2 数组下标 

Select a certain subset of elements inside a matrix


•What’s the answer from MATLAB after typing?
>> A(8)

  9
>> A([1 3 5])

  1  31  17 
>> A([1 3; 1 3])

 

 
>> A(3,2)

  2
>> A([1 3], [1 3])

1.3 Colon Operator

•Want to create a long array:A= [12 3 … 100]
•Creates vectors or arrays, and specify for iterations
•Syntax:


•What’s the answer from MATLAB after typing?
>> B = 1:5

1 2 3 4 5 
>> B = 1:2:5

1 3 5
>> B = [1:5; 2:3:15; -2:0.5:0]

1        2     3      4       5

2        5     8     11     13

-2    -1.5   -1    -0.5    0  

>>str= 'a':2:'z'

a b c ... z

 

1.4 Array Concatenation

1.5 Array Manipulation

数组运算

>> x1=A+a

每个都加2

>> y1=A+B

对应位想加


>> x2=A/a

每位都除以a

>> y2=A*B


>> x3=A./a

对应位相乘a

>> y3=A.*B

对应位相乘


>> x4=A^a

a个A相乘

>> y5=A./B

对应位想除

>>C=A'

转置矩阵

 

 Some Special Matrix

一些特殊的矩阵

Matrix Related Functions

 一些矩阵函数

>>max(A)

>>max(max((A))

结果是   9

也就是对上面的[9 8 7 ] 中取最大的

>>sort(A)

从小到大  按照列排序

>>sortrows(A)

从小到大  按照行排序
>> min(A)

参照最大

>> size(A)

结果是  3 3  表示有3行3列
>> sum(A)

对每列求和

猜你喜欢

转载自www.cnblogs.com/liu-wang/p/9027016.html