matlab 数列变矩阵,matlab-变量类型-数组-矩阵(示例代码)

1 变量类型

1.1基本

20180512110538173903.png

1.2 特殊变量

ans

•i,j: complex number

•Inf: 无穷大

•eps: 2.2204e-016

•NaN: not a number

•pi:pai

20180512110538496148.png

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

1.3 numeric display format

20180512110538636764.png

1.4 some useful functions

•clc: clear command windowdisplay

•clear: remove all variables in the workspace

•who: variables in the workspace

•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

20180512110538790075.png

•What’s the answer from MATLAB after typing?

>> A(8)

9

>> A([1 3 5])

1  31  17

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

20180512110538827182.png

>> A(3,2)

2

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

20180512110538893584.png

1.3 Colon Operator

•Want to create a long array:A= [12 3 … 100]

•Creates vectors or arrays, and specify for iterations

•Syntax:

20180512110538951197.png

•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

20180512110539000999.png

1.4 Array Concatenation

20180512110539079119.png

1.5 Array Manipulation

数组运算

20180512110539185557.png

>> x1=A+a

20180512110539326173.png

每个都加2

>> y1=A+B

20180512110539404293.png

对应位想加

>> x2=A/a

每位都除以a

>> y2=A*B

20180512110539471672.png

>> x3=A./a

对应位相乘a

>> y3=A.*B

对应位相乘

>> x4=A^a

a个A相乘

>> y5=A./B

对应位想除

>>C=A‘

转置矩阵

20180512110539546862.png

Some Special Matrix

一些特殊的矩阵

20180512110539667948.png

Matrix Related Functions

一些矩阵函数

20180512110539734350.png

>>max(A)

20180512110539793917.png

>>max(max((A))

结果是   9

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

>>sort(A)

从小到大  按照列排序

>>sortrows(A)

从小到大  按照行排序

>> min(A)

参照最大

>> size(A)

结果是  3 3  表示有3行3列

>> sum(A)

对每列求和

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值