文章目录
- (〇)前言——【先看看】
- (一) 【Basic operation(introduce MATLAB)】——【基本操作(介绍MATLAB)】:
- (二) 【Matlab as calculator】,【Array operation】——【Matlab作为计算器】、【数组运算】:
- (三) 【Script writing】,【structured programming】,【User-defined function】——【脚本编写】、【结构化编程】、【自定义函数】:
- (四) 【Variables:string,strcture,cell】,【Date access】——【变量:字符串、结构、单元格】、【数据库访问】:
- (五) 【Basic plotting】,【Graphical object properties】——【基础绘图】、【图形对象属性】:
- (六) 【Advanced 2D plots】,【Color space】,【3D plots】——【高级2D绘图】、【色彩空间】、【3D绘图】:
- (七) 【Graphical user interface】——【图形用户界面】:
- (八) 【introduction to digital image】,【read and show images】,【image arithmetic】——【数字图像概论】、【图像读取与显示】、【图像算法】:
- (九) 【Image thresholding】,【Background estimation】,【Connected-component labeling】——【图像阈值化】、【背景估计】、【连通分量标注】:
- (十) 【Polynomial differentiation and integration】,【Numerical differentiation and integration】——【多项式微分与积分】、【数值微分与积分】:
- (十一) 【symbolic approach】,【numeric root solvers】,【recursive function】——【符号法】、【数值根求解】、【递归函数】:
- (十二) 【Statistics】——【统计】:
(〇)前言——【先看看】
本文是对MATLAB一些应用的介绍。可以帮助理解MATLAB的功能和用法
后面会慢慢更新具体的MATLAB在工程中的一些应用
学习于B站视频,整理出来一些学习资料。英文版的,也可以提升英语能力
这里也推荐一些最基础入门的学习网站
http://c.biancheng.net/matlab/
https://www.ilovematlab.cn/resources/
需要word版的可以下载附件资源
一些源代码也会在我的另一份博文里提供
源代码https://blog.csdn.net/Nirvana_Tai/article/details/105391688
有交流或者建议可以联系我 QQ:1756170618
(一) 【Basic operation(introduce MATLAB)】——【基本操作(介绍MATLAB)】:
i. search Function name by online or help
ii. variable,and search its type in double click or input whos(which is more
in detail than who)
iii. π=pi,∞=Infinitely small=eps,NaN:not a number,i,j=complex number
iv. sqrt: square root
v. no use built-in function or keyword as variable name, if you use it, must clear this variable name
vi. format+bank(short/long/shortE/rat and so on)
bank: two decimal places
short: four decimal places
long: many decimal places
scientific notation +E
traction rat
vii. command line terminal:use ;
viii. Press the arrow key to bring it up and down command history
ix. Input “clear”to remove all workspace,input”clc”to remove all command window
(二) 【Matlab as calculator】,【Array operation】——【Matlab作为计算器】、【数组运算】:
i. Basic:use “[ ]”to express array
ii. Row vector—[ ];column vector—[ ; ; ; ; ]
iii. Inner product;outer product This like this:[1 1 1][1;1;1]is inner product, [1;1;1] [1 1 1]is outer product.
iv. Matrix:use semicolon to divide each row
v. Indexing:input array name with(row,column)
Addition:input A(1,:) to index all value in third row
vi. Replace entries:
If want to delect which row or column,using A(x,:)=[ ]
vii. Colon operator:equal difference series
Like A=1(first number value):1(equal difference):50(final number value)
viii. Array concatenation:use F=[A(array one) B(array another)]
ix. Array manipulation:look out:AB different with A.B
Array +constant:Ax Array transposition:A’
x. Some special Matrix
eye(n):nn identity matrix
zeros(n1,n2):n1n2 zero matrix
ones(n1,n2):n1n2matrix with every entry as 1
diag( ):diagonal matrix
xi. Some Matrix related functions
max(A):index and show max entry in every column
max(max(A)): index and show max entry in array
sum(A):sum each entry in every column
mean(A):mean in every column
sort(A):sort entry’s size in each column
sortrows(A):sort first column’s entries and sort it with rows
size(A):the size of matrix
length(A):the column’s length
find(A==x)
xii. some operation
Matrix determinant: det(A)
Inverse matrix: inv(A) or A^-1
adjoint matrix: A*=det(A)inv(A)
prod(1:n)=n!
1e100=110^100
(三) 【Script writing】,【structured programming】,【User-defined function】——【脚本编写】、【结构化编程】、【自定义函数】:
i. Script editor: % as annotation,%% to divide section
Debug: use breakpoint
Smart indent: inverse blank space
ii. Script flow: typically scripts run from the first line to the last
Flow control,
relational operators: ~=:not equal to
&&:and ||:or
It is logical, because it belong to Boolean
iii. If/elseif/else: ,”elseif”and”else” are optional
[‘even’ even number ’odd’ odd number]
iv. Edit grammar
‘disp’ is means ‘printf’which in C language
‘input_(xxx)’ is means ‘int()’
v. Switch :
vi. While:
vii. For:
viii. Pre-allocating space to variables: if not pre-allocating space to variables will spend more
time to debug. Can record time.
ix. Break:
x. Tips for script writing:
Use semicolon(😉:inhibit unwanted output
Use ellipsis(…):to make scripts more readable
Use smart forming
Use ‘ctrl+c’ to stop operate
xi. Content of matlab built-in functions:
Looking for source code:use “edit(which(‘function.m’))varargin
Function have keyword,output,file name,input
xii. User define function:
Like ‘freebody’
[.*(./)is more useful]
Some functions:input,isemply,break,disp,num2str
xiii. Function default variables:
Nargout:number of function input arguments
Varargin:variablr length input argument list
Varargout:variablr length output argument list
xiv. Function handles: ’f’ is a function handle
(四) 【Variables:string,strcture,cell】,【Date access】——【变量:字符串、结构、单元格】、【数据库访问】:
i. Matlab date(variable) types:
Use ‘int8()’ to transform types
ii. Transform the char to hex(ASCII): using ‘uint16( )’
iii. Logical operations and assignments:
Seek,compare and input
iv. Structure: as (student.name)
v. Adding information to a structure: add (2)… like(student(2).name)
vi. Structure functions:
Like (fieldname( )) and (refiled( ))
vii. Nesting structures:
To input a structures which be made of many other structures.
Like this:
xiii. Cell array:
a) Another method of soring heterogeneous date,it is similar to matrix but each entry contains different type of date.
b) Declaresd using {}
Or can use method like “A{1,1}=[1,2,3;2,3,4;3,4,5]…”
xiv. Accessing Cell array:
Use A{1,1} to get {1,1}array.
Use A{1,1}(1,1) to get {1,1}array’s (1,1) number
xv. Cell array functions: click this website to look for cell array functions
a) num2cell:
b) mat2cell:
xvi. Multidimensional array:
a) Include rows,columns,layers
You can use to make it,but it is flexible and inefficient
b) Array concatenation: cat()
Like this:
xvii. Reshape:
xviii. Checking variable and variable status:
Using ‘isfunction’ to determine
xix. File access:
A. High-level file input/output:
a) save() and load():
- save(all) workspace date to a file:
- load date stored in a file:
b) Excel file reading: xlsread()
c) Excel file writing: xlswrite()
‘04Score.xlsx’ is filename 1 is sheet
M is variable ‘E2:E4’ is location
Mean(A) is to calculate each column in A
Mean(A’) is to calculate each row in A and show with 13
Mean(A’)’ is to calculate each row in A and show with 31
d) Getting text in excel spreadsheet:
Getting both the text and numbers:
B. Low-level file input/output:
a) Read and write file at the byte or character level.
b) File I/O functions: click
c) Writing sine values into a file:
d) Read and write through formatted I/O:
e) Reading from files: fscanf(fid, , )
Check if it is the end of file:
(五) 【Basic plotting】,【Graphical object properties】——【基础绘图】、【图形对象属性】:
i. Plot()
If you not input instruct, the new plot will take place of the old ones
ii. Hold on/off: to have both plots in one figure
iii. plot style: plot(x,y,’str’) ,using the format defined in str(check linespec)
iv. legend( ):add legend to graph
v. title( ) and ?lable( )
slash pi(\pi) to show as π; use “{ }”to show special sign
vi. text( ) and annotation( ):
linspace:Generate linearly spaced vector
vii. figure adjustment:
【Graphical objects: Figure object, Axes object, Line object】
Figure property: in the figure’s editor
viii. Modifying properties of an object:
a) Identifying the handle of object:
b) Fetching or modifying properties:
c) Get object properties:
d) Setting axes limits:
Using set(gca,’XLim’,[0,2*pi]);
e) Setting font and tick of axes
Using set(gca,’FontSize’,25);
f) Line specification:
Using set(h,’LineStyle’,’-‘,…
‘LineWidth’,7.0,’Color’,’g’);
ix. Marker specification:
Face and edge colors of the marker.
x. Multiple figures:
Create a figure window by calling
Ps: the difference between gcf and gca
xi. Figure position and size:
xii. Several plots in one figure:
Several small plots“in a figure”
xiii. Control of Grid,Box,and Axis:
xiv. Saving figures into files:
xv. grid on; means show grid
axis square sets the current coordinate figure to a square. The ratio of the horizontal axis to the vertical axis is 1:1
axis equal sets the scaling coefficient of the horizontal and vertical axes to the same value
(六) 【Advanced 2D plots】,【Color space】,【3D plots】——【高级2D绘图】、【色彩空间】、【3D绘图】:
i. What forms appropriate to you:
ii. Special plots:
iii. Logarithm plots:
iv. Plotyy(): SC
v. Histogram: SC
vi. Bar charts: SC
vii. Stacked and Horizontal Bar Charts: SC
viii. Pie charts:
ix. Polar charts:
The SC of N polygon
x. Stairs and Stem charts:
The exercise’s SC,which as followed.
xi. Boxplot and Error Bar:
xii. fill()
- stop sign: SC
fill() is to fill the color in the figure
xiii. Color space:
click to check color chart:
color chart:
xiv. Visualizing date and an image : imagesc()
-
Display values of a matrix as an ‘image’ SC
-
Color bar and scheme:
Nature colormap(cool) colormap(hot)
4. Built-in Colormaps
xv. 3D Plots:
xvi. More 3D Line Plots:
xvii. Principles for 3D Surface Plots:
A. Surface plots:mesh() and surf(): SC
xviii. contour():
projection of equal heights of 3D plot onto a 2D plane.
xix. meshc() and surfc():
combination of surface/mesh and contours
xx. View Angle: view()
Vary the view angle in the script below
the latter SC
xxi. Light : light()
Light('Position’,[ , , ])
Set(L1.’Position’,[ , , ])
xxii. patch()
a graphical object containing polygons
xxiii. Matlab plots can be very professional!
its SC
(七) 【Graphical user interface】——【图形用户界面】:
i. Matlab GUI programs:
ii. Starting a GUI programs:
iii. GUI figure
Display the names of the GUI components
- Select File>Preferences>GUIDE
- Check”show names in compenent palette”
iv.
to reserve some files about GUI
v. Align the components:
Select Tools>Align objects
vi. Label the Push Buttons:
Select View>Property Inspector [double click]
vii. GUI script structure:
Function untitled_OpeningFcn
Insert under this module: as followed
viii. Callback of an Object:
Make some buttons callback to different running. As followed.
ix. What if we have two axes?
The latest figure will show on.
x. handles-Parents of the GUI Objects:
xi. setting the axes for Plotting:
xii. Review-set() and get():
get() acquires properties
set() set properties
xiii. Using handles to store variables:
xiv. Compiling the GUI program
Deploytool
(八) 【introduction to digital image】,【read and show images】,【image arithmetic】——【数字图像概论】、【图像读取与显示】、【图像算法】:
i. Digital image and its Acquisition:
ii. Types of digital image:
Color, gray scale, binary
iii. Where does the color come from:
iv. Typical RGB image:
v. Elements of images:
vi. Read and show an image:
Read an image: imread()
Show an image: imshow()
vii. Image variable in workspace:
viii. Image info:
ix. Image viewer: imtool(‘pout.tif’)
Get pixel information in image viewer
x. Image processing:
Any form of signal processing for which the input is an image
xi. Image arithmetic:
xii. Image multiplication: immultiply()
xiii. Image addition: imadd()
xiv. Image Histogram: imhist()
YLable is number of pixel,XLable is graylevel
xv. Histogram Equalization: histeq()
xvi. Geometric transformation:
Moving the coordinates of the pixels in an image
xvii. Geometric transformation Matrices(2D)
xviii. Image rotation: imrotate()
xix. Image Rotation:
xx. Write image: imwrite():
(九) 【Image thresholding】,【Background estimation】,【Connected-component labeling】——【图像阈值化】、【背景估计】、【连通分量标注】:
i. Image thresholding:
A gray-level image can be turned into a binary image by using a threshold.
ii. graythresh() and im2bw(): SC
graythresh() computes an optimal threshold level
Im2bw() converts an images into binary image
iii. Issues of the Binary image:
existing sparkles in the background
some grains are missing
iv. Background estimation:
v. Background substraction:
vi. Thresholding on background removed image:
vii. Connect-component labeling:
viii. Connect-component labeling: bwlabel()
ix. Color-coding objects: label2rgb() SC
x. Object properties: regionprops() SC
xi. Interactive selection: bwselect() SC
(十) 【Polynomial differentiation and integration】,【Numerical differentiation and integration】——【多项式微分与积分】、【数值微分与积分】:
i. Differentiation:
ii. Polynomial differentiation:
iii. Representing polynomials in MATLAB:
iv. Values of polynomials: poluval() SC
v. Polynomial differentiation: polyder()
vi. Convolution: conv()
Exercise: SC
vii. Polynomial integration:
K is a constant
viii. Polynomial integration:
ix. Numerical differentiation:
x. Differences: diff()
Calculates the differences between adjacent elements of a vector
xi. Numerical differentiation using diff()
xii. How to find the f’ over an interval [0,2pi]? SC
xiii. Various step size
xiv. Second and Third derivatives:
xv. Numerical integration:
xvi. Numerical Quadrature rules:
xvii. Midpoint rule:
xviii. Midpoint rule using sum()
xix. Trapezoid rule:
xx. Trapezoid rule using trapz()
xxi. Second-order rule:1/3 Simpson’s
xxii. Simpson’s rule:
xxiii. Comparison:
xxiv. Review of Function Handles(@)
A handle is a pointer to a function
Can be used to pass functions to other functions
xxv. Numerical integration: integra1()
xxvi. Double and Triple integrals:
(十一) 【symbolic approach】,【numeric root solvers】,【recursive function】——【符号法】、【数值根求解】、【递归函数】:
i. Problem statement:
ii. Symbolic root finding approach:
iii. Symbolic root finding: solve()
iv. Solving multiple equations:
v. Solving equations expressed in symbols:
vi. Symbolic differentiation: diff()
vii. Symbolic integration: int()
viii. Symbolic vs. Numertic:
ix. fsolve:
x. fzero:
xi. finding roots of polynomials: roots()
xii. how do there solves find the roots:
xiii. Numeric root finding methods:
xiv. Bisection method(Bracking)
xv. Newton-Raphson method(open)
xvi. Bisection vs. Newton-Raphson
xvii. Recursive function
xviii. Factorial recursive function
(十二) 【Statistics】——【统计】:
i. Statistic
The science of”date”
Involving the collection,analysis,interpretation,presentation,and organization of date
ii. Main statistical methodologies
iii. Summary mersures:
iv. Mean,Media,Mode,and Quartile
v. Range and interquartile range
vi. Variance and Standard Deviation:
vii. Figures are always more poweful:
viii. Boxplot exanple:
ix. Skewness:
x. Skewness: skewness()
xi. Kurtosis:
xii. Statistical hypothesis testing
xiii. Hypothesis testing procedure:
xiv. Terminology in Hypothesis testing:
xv. t-test example:
xvi. Two-tailed significance test:
xvii. One-tailed significance test:
xviii. Common Hypothesis tests:
Matlab functions