Screenshot PPT document from Guo Yanfu teacher and video courseware B station
Basic Operations
-
+, -, *, /, ^. ln the operating system is a log. log (2) to the base 2. e: When e is the exponent exp ()
-
sin (cos (pi)): calculating step; ans = con (pi), sin (ans)
-
Variable variable: do not declare variables (unlike C). From left to right assignment.
Keywords can not be when the variable: inf is infinite;
eps is a very small number;
NaN: Number The not A;
i, where J is the plural use;
PI
with iskeyword know which keyword -
clear in the workplace can eliminate the variable, you need to remember that behind the increase in variable eliminated, otherwise it will eliminate all
CLC: clear the Command Run the display window
the WHO: the Variables in at The workplace
whos: variable of Information at The workpalce -
FORMAT Format
Short
Long
Shorte: E is in scientific notation, where numeral 10 denotes the power
Longe
Bank: 2 decimal places
hex: 16 hex
rat: the value converted into rational
-
Semicolon ";" effect: does not display the calculation result
ARRAY ( Vector and Marix )
Enter the Matrix and vector
The matrix a = [1 2; 3 4]: Wrap semicolon ";", the trailing column assignment is to be usedBlankYou can also use
comma","
array indexing
1
.
.
2.
Replacing Entries
删除行,同理可以删除列
Colon Operator
j:k ——>[j,j+1,j+2,…,j+m]
j:k:i ------>[j,j+k,j+2k,…j+m*k] 和fortran的区别一下,fortran的等差是i
Array Concatenation
Array Manipulation矩阵的四维运算
点乘==.*==:相对应项相乘
除/:乘逆矩阵
’ :转置矩阵
A^2和A.*2不一样
Some Special Matrix
2是表示单位矩阵的维数,diag是对角线矩阵
max:输出矩阵中每一列最大的元素
max(max(A)):输出最大的元素
min同理
sum:每一列的和
mean:每一列的平均值
sort:排序,每列元素按小到大排序
sortrow:行排序,把最小的行放到第一行
size:输出矩阵的维数
length:输出行数
find:找矩阵中某一元素的位置。如find(A==0)
APPLICATION OF MATLAB(IF,while,do,函数…)
Script Editor
-
储存成.m
-
运行代码
`for i=1:10
x=linspace(0,10,101);
plot(x,sin(x+i));
print(gcf,’-deps’,strcat(‘plot’,num2str(1),’.ps’));end`
点击运行或者F5,储存后即可得到答案。 -
记不清楚函数名可以点击上界面的FX
-
注解%,
%%:section,分区块 -
break point:debug时用,
控制语句
rem(a,b):a除以b的余数
写另一个程序的时候记得清楚之前的数据
计算之前pro-allocating可以节省时间
tips:
2. clear
3. clc
4. ;
5. …
6. ctrl+c
Function
USER DEFINE FUNCTIONS
MATLAB IN ENGINEERING
变量
- 变量转换
- CHARACTER
s1=‘h’
s2=‘happy’
s3=[s1 s2] —— hhappy
s4=[s1;s1] —— 必须是字符数相同的
uint16(s1)显示s1的ascii码值
比较字符串 strcmp(s1,s2) 相同返回1,不同返回0
把一个字符串逆输出
- STRUCTURE
输出单个元素
fieldnames: the structure inside the name caught out
rmfield: The refield (student, 'id') is the structure where id deleted
converts an array of structures to struct2cell cellular array, the cellular arrays to structural array ( or cell2struct structure called a vector) of.
getfield: Gets the value of a field, or fields in columns
isfield: determining whether the input is a member of an array of structures ...
call format: f = isfield (s, ' fieldname') comprises checking whether the specified structure by the S domain fieldname, if included, Back logic 1; fieldname If no domain structure or S type is not, returns to logic 0.isstruct: used to determine, whether the input is an array of structures. Format tf = isstruct (A) if A is an array of structures, the tf = 1, otherwise, tf = 0;
Structure can be nested
- ARRAY the CELL
the Cell announcement
Two kinds of methods are declared using
Read cell array
num2cell() and mat2cell()
Multidimensional array
row, column, layer (layer)
CAT (concatenation): connecting
reshape the shape change matrix
chestnut
Check if something is. .
DATA ACCESS
- FILE ACCESS
save()and load()