Introduction to Getting Started with Matlab

  • MATLABYes is Matrix Laboratoryan abbreviation for Matrix Lab . It was produced in the late 1970s. It is an interface program written for students to use EISPACK and LINPACK when Cleve Moler, director of the Computer Department of the University of New Mexico in the United States, taught linear algebra courses to students. In 1984, it was officially introduced to the market by MathWorks and has been continuously updated and improved.
  • MATLABIt is a simple and easy-to-use mathematical software released by American Mathworks Corporation. It mainly faces the high-tech computing environment of scientific computing, visualization and interactive programming. It has powerful data processing capabilities and excellent graphics processing functions . Learning and mastering it will help people free themselves from heavy mathematical calculations and devote more energy to the study and research of mathematical theories.

【que】Why do you need data analysis?
[ans] Transform large volumes of complex data into actionable information.

insert image description here
insert image description here

MATLAB work interface

default layout

MATLAB R2023aThe default layout of is shown in the following figure:

insert image description here

  • The menu bar above is a tool bar , including 文件, 变量, 代码, SIMULINK, 环境and 资源several parts.
  • The right window is the command window ( Command Window), which is used to input operation commands ;
  • The upper left window is the current folder , and the upper part is the path where the current folder is located.
  • The lower left window is the workspace management window ( Workspace), which displays the variable names, data structures, bytes and types of all variables currently stored in the memoryMATLAB . Different variable types correspond to different variable name icons.

custom layout

Sometimes due to misoperation, MATLABthe working interface of is changed. To restore to the default working interface , just change the 环境in to .布局默认

You can customize the layout 环境in in the toolbar , and you can also select the content to be displayed in . For example, if the toolbar above is missing, check in to display it.布局显示显示工具条

insert image description here

history window

The history record window ( Command History), keeps the history record of all commands since installation , and marks the use time for the convenience of users to inquire. Double-click a command line to execute the command in the command window ;

insert image description here

call previously run statement

The command history here, if selected 弹出, the effect is to press the arrow keys on the keyboard to select the previously executed statement, and press enterto select;

insert image description here

If selected 停靠, the effect is as shown in the figure below:

insert image description here

At this point, select a used command on the right, and then double-click to run the command again.

common operation

1. Clear operation

>> clc %清除命令窗口中的所有内容
>> clear %清除工作空间的所有变量
>> clear all %清除工作空间的所有变量,函数和 MEX 文件

>> clf %清除图形窗口内容
>> close %关闭当前的 Figure 窗口
>> close all %关闭所有的 Figure 窗口

These commands are generally written on the first linematlab of the program .

Among them, the symbol %represents a comment , and does not run in the command window.

MEXThe file is a matlabC language (or fortran) derivative program that can be called in the environment, and mexthe compiled result is actually a dll file with the output function mexFunction.

clc effect

Compare the two pictures below to observe clcthe effect of clearing only the command window, but not the variables in the workspace :

insert image description here

clcAfter that, the variables in the workspace are still there.

insert image description here

clear effect

Compare the two pictures below to observe clearthe effect of only clearing the variables in the workspace, but not clearing the command window :

before clear

clearAfter that, the commands in the command line window are still there.

after clear

clf

clf help documentation

insert image description here

【Function description】

  • clf: Deletes all children in the current figure that have a visible handle . (like their HandleVisibilityproperty is set to on)
  • clf(fig): Deletes all children in the specified figure that have a visible handle .
  • clf(‘reset’): Deletes all children of the current figure regardless of their handle visibility . It also resets figure properties to their default values , except for Positionthe , Units, PaperPositionand PaperUnitsproperties.
  • clf(fig,‘reset’): Deletes all children of the specified figure and resets its properties .
  • f = clf(…): A figure can be returned using either of the above syntaxes . Used when the image attribute is off, because non-integer handles are not availableIntegerHandle when using the reset option (eg set to the default value of on).IntegerHandle

【Visible handle】If HandleVisibilitythe property of the object is set to 'on', the handle is clfvisible to .

  • When called from the Command Window or a callback routine clf, this function deletes only those objects whose HandleVisibilityproperty is set to .'on'
  • It will not delete objects whose HandleVisibilityproperty is set to 'callback'or 'off'.

clf effect

close effect

close: close the current Figurewindow

insert image description here

insert image description here

2. help

  • request help file
>>help 请求内容

like:

>>help elfun %关于基本函数的帮助信息
>>help exp %指数函数 exp的详细信息

insert image description here

  • Help file in hypertext format
>>doc 请求内容

like:

>>doc elfun %以超文本格式显示关于基本函数的帮助信息
>>doc exp %以超文本格式显示关于指数函数的帮助信息

insert image description here

  • ask for help
 >>lookfor 请求内容

When you want to find an instruction with a certain function but don't know the exact namehelp , the ability of the command is not enough, and you can use lookforthe command at this time. lookforAccording to the complete or incomplete keywords provided by the user, a group of related instructions can be searched out.

like:

>>lookfor integral %查找有关积分的指令
>>lookfor fourier %查找能进行傅里叶变换的指令
  • request a demo
>>demo 请求内容

【Summarize】

  • Commands help, doc, and lookforhave their own characteristics, among which helpand docare only displayed differently.
  • helpdocThe request content of , must be complete and accurate , while lookforthe subsequent request content can be incomplete .

Data Structures in Matlab

insert image description here
Create the array manually :
insert image description here

Matrix data access

A ( j , k ) A(j, k) A ( j ,k ) , wherejjj means thejjthline j , kkk means thekkthk列。A ( end , 1 ) A(end,1)A(end,1 ) represents the matrixAAThe data in the first column of the last row of A. A ( 1 : end , 3 ) A(1:end,3)A(1:end,3 ) represents the matrixAAThe data in the third column of A from the first row to the last row. A ( : , 3 ) A(:,3)A(:,3 ) Neutral: :: Defaults to all lines.
insert image description here

Built-in functions for vectorized operations

insert image description here

Constants and Variables

1. Constant table

MATLABThe language itself has some predefined variable values, and these special variables with specific values ​​are called constants .

constant Indicates the value
pee peepi pi \piPi
i n f inf inf positive infinity
N to N NaNN to N Represents an indeterminate value
i , j i,j ij imaginary unit
eps epseps minimum number of computers
r e a l m a x realmax realmax largest available positive real number
r e a l m i n realmin realmin smallest available positive real number

2. Variable naming rules

MATLABVariables in the language are composed of letters, numbers, and underscores . The main naming rules are:

  • start with a letter;
  • case sensitive.

3. Common forms of sentences

MATLABThere are two most common forms of statements:

  • >>变量 = 表达式;

The running result is displayed as 变量 = ….

  • >>表达式;

The running result is displayed as ans = ….

Among them, ansrefers to the current calculation result . If the user does not set a variable for the expression during calculation, the system will automatically assign the current result to ansthe variable. like:

insert image description here

arithmetic operator

1. Addition, subtraction, multiplication, division, power

  • MATLABThe input of addition, subtraction, multiplication operators is consistent with the usual computer input.
  • The division operation is divided into left division ( \) and right division ( /), 2/3yes 2 除以 3, but 2\3actually is 3 除以 2. To avoid confusion, the former is taken for general division operations.
  • The exponentiation operator is on the computer keyboard ^.
operator 矩 阵the MATLABinput 数 组the MATLABinput
add + +
reduce - -
take * .*
remove / ./
power ^ .^

2. Matrix operations and array operations

MATLABThe operation is divided into two types : matrix operation and array operation .

In linear algebra, a rectangular array of rows andm columns is called a matrix. nlike:

insert image description here

A matrix with only 1 row or 1 column is called a vector or array.

MATLABThe basic data unit of is a matrix , therefore, the normal operation is a matrix operation , and the operation of adding a dot before the operator is an array operation .

In MATLABactual operation, if you deliberately distinguish whether to add a dot before the operator, it may complicate the problem and create unnecessary confusion. Conforming to people's habitual thinking is MATLABa major advantage of , therefore, when operating, you can first input without adding a dot. If there is no other error in the input, but the command cannot be run, then the operation may be an array operation. Try adding before the corresponding operator ..

like:

insert image description here

logical operators

Logical operation is MATLABan operation form of array operation in , and it is also an operation commonly used in almost all high-level languages.

symbolic operator Function Function name
= = == == equal e q eq eq
∼ = \sim= ∼= not equal to no noi.e _
< < < less than l t lt lt
> > > more than the g t gt gt
< = <= <= less than or equal to le lel e
> = >= >= greater or equal to g e ge ge
& \& & logic and a n d and and
∣ | logical or o r or or
∼ \sim logical NOT n o t not not

【Explanation】In arithmetic operations, comparison operations and logic AND, or, and NOT operations, their priority relations are: comparison operations, arithmetic operations, logic AND, or NOT operations .

Other common symbols

symbol MATLABenter use
comma , Separate variables, expressions, columns of matrices
semicolon ; Separate command lines without displaying run results, separate rows of matrices
apostrophe ' ' define string
colon : x = a : b : cRepresents a value xfrom ato in steps ofbc
equal sign = variable assignment
percent sign % command comment
three periods ... Continuation
Parentheses ( ) Differentiate the order of operations
Square brackets [ ] form a matrix or vector

[Example] MATLABEnter matrix A in = [ 1 2 3 4 5 6 7 8 9 ] A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}A= 147258369

MATLABThe procedure is as follows:

>>A = [1,2,3; 4,5,6; 7,8,9] %行与行之间用分号分隔,每行的(列)元素间用逗号分隔

insert image description here

Guess you like

Origin blog.csdn.net/xiaoyuting999/article/details/131652703