MATLAB study notes (a) Basic Operation

Screenshot PPT document from Guo Yanfu teacher and video courseware B station

Basic Operations

  1. +, -, *, /, ^. ln the operating system is a log. log (2) to the base 2. e: When e is the exponent exp ()

  2. sin (cos (pi)): calculating step; ans = con (pi), sin (ans)

  3. 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

  4. 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

  5. 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
    Here Insert Picture Description
    Here Insert Picture Description

  6. Semicolon ";" effect: does not display the calculation result
    Here Insert Picture Description

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","
Here Insert Picture Description

array indexing

1
. Here Insert Picture Description
. Method One: comma
Here Insert Picture Description

2.
Method Two: There is no comma
Here Insert Picture Description
Here Insert Picture Description

Replacing Entries

Here Insert Picture Description
Here Insert Picture Description
删除行,同理可以删除列
Here Insert Picture Description

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

Here Insert Picture Description
空格和逗号的效果相同

Array Manipulation矩阵的四维运算

x4和x5不一样
在这里插入图片描述
点乘==.*==:相对应项相乘
除/:乘逆矩阵
’ :转置矩阵
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的余数

  • 在这里插入图片描述

  • 在这里插入图片描述

  • List item

  • List item

写另一个程序的时候记得清楚之前的数据
计算之前pro-allocating可以节省时间在这里插入图片描述

List item
tips:
2. clear
3. clc
4. ;
5. …
6. ctrl+c

Function

USER DEFINE FUNCTIONS

  1. List item
  2. 在这里插入图片描述

MATLAB IN ENGINEERING

变量

  1. 变量转换
    在这里插入图片描述
  2. CHARACTER
    s1=‘h’
    s2=‘happy’
    s3=[s1 s2] —— hhappy
    s4=[s1;s1] —— 必须是字符数相同的
    uint16(s1)显示s1的ascii码值
    在这里插入图片描述
    比较字符串 strcmp(s1,s2) 相同返回1,不同返回0
    把一个字符串逆输出
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
  3. 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在这里插入图片描述

  1. 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

  1. FILE ACCESS
    在这里插入图片描述
    save()and load()

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Paint Elementary

Released six original articles · won praise 0 · Views 212

Guess you like

Origin blog.csdn.net/qq_45793719/article/details/104125914