1 变量类型
1.1基本

1.2 特殊变量
ans
•i,j: complex number
•Inf: 无穷大
•eps: 2.2204e-016
•NaN: not a number
•pi:pai

注意:关键字是可以做变量的
1.3 numeric display format

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

•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)
对每列求和
原文:https://www.cnblogs.com/liu-wang/p/9027016.html
本文详细介绍MATLAB中的变量类型、数值显示格式及常用函数,并通过实例讲解数组定义、下标选取、数组运算等核心操作,同时介绍了几种特殊矩阵及其相关函数。
481

被折叠的 条评论
为什么被折叠?



