Basic knowledge of matlab

Basic mathematical operation symbols

SymbolfunctionSymbolfunction
+addition-subtraction
*Matrix multiplication.*Multiplication, dot multiplication, that is, array multiplication
/Right division./Right division of array
\be demoted'\'.Array left division (there is no single quotation mark here)
^Power.^Array power
'Matrix conjugate reprint.'Matrix transpose

Simple example of basic operation

>>%Definition matrix A Sum matrix B
>>A=round(rand(3)*10)
A=
	9	4	4
	3	5	7
	4	9	1
>>B=magic(3)
B=
	8	1	6
	3	5	7
	4	9	2
>>%Cross multiplication and dot multiplication of matrices
>>C1=A*B
C1=
	100	65	90
	119	133	123
	47	56	77
>>C2=A.*B
C2=
	72	4	24
	21	45	63
	8   81	2
>>%Left division and right division of matrices
>>D1=A./B
D1=
	1.1250	  4.0000    0.6667
	2.3333	  1.8000    1.2857
	0.5000   1.0000    0.5000
>>D2=A.\B
>D2=
	0.8889   0.2500  1.5000
	0.4286   0.5556   0.7778
	2.0000   1.0000   2.0000
>>%Matrix power 
>>E1=A.^2
E1=
	81	16	16
	49	81	81
	4	81	1
>>E2=A^2
E2=
	117	108	76
	144	190	118
	83	98	90

As can be seen from the example, no matter which operation method (multiplication, division and power), it is marked with "." The operation mode of represents the operation on the elements of the matrix. For a matrix, the right division of a matrix is a division in a general sense, while the left Division has a symmetrical meaning, that is, A./B=B.\A.

Common punctuation in the command line

SymbolnameFunction and significance
'space'SpaceSeparator between input quantities (these spaces between variables will be ignored in the command window); Enter the separator between array elements
commaTo display the separation between the calculation results and other commands; Separator between input quantities or between array elements
.spotIn numerical calculation, it can be used as a decimal point; In the process of array operation, it can be used as the indicator of element operation
semicolonAt the end of the command line, it means that the calculation result will not be displayed after the calculation; Or as a separator between array rows when entering an array
: colonWhen generating a one-dimensional array, it can be used as a separator; All sequences composed of all elements used for single subscript reference; Separator during loop operation
%Percent signIt is located at the beginning of the command line, indicating that the line is a comment line, which increases the readability of the input or deformed file. All contents after the percent sign are comment contents, which are not compiled and displayed in the command window
''Single quote pairUsed to define a string
()ParenthesesChange the priority order in the operation process; Used in function calls; Index as array
[]square bracketsDefinition matrix
{}Curly bracketDefine cell array, special character parentheses in graphics
_UnderlineHyphens used when defining variables, functions, or files; The leading symbol of the subscript in a graph
...Continuation numberWhen the command in the input command window is long, you can enter more than 3 point numbers on the first line and continue to enter the command on the next line to complete the input and execution of the long command
@"At" NoPut it in front of the function name to form a function handle; As the leading character of an anonymous function
!exclamatory markCall operating system operation

Common operations and editing commands in the command window

commandFunction and significancecommandFunction and significance
cdShow or change working directorypackDefragment memory
clcClear command windowpathShow search directory
clearClear variables in workspacequitExit MATLAB
clfClear graphics windowsaveSave memory variables
disaryLog file namingtypeShow file contents
dirDisplays the files in the current directorywhatList MATLAB files in the directory
dispDisplays the contents of a variable or textwhichLocate the path to the MATLAB file
echoCommand window information display switchwhoLists the variables for the workspace
holdDrawing hold commandwhosDetailed list of workspace variables
loadLoads variables in the specified file

MATLAB operation command demonstration

>>who
Your variables are:
A	B	C1	C2	D1	D2	E1	E2
>>whos
	Name	Sive	Byte	Class
	A		3*3		  72	double arry
	B		3*3		  72	double arry
	C1		3*3		  72	double arry
	C2		3*3		  72	double arry
	D1		3*3		  72	double arry
	D2		3*3		  72	double arry
	E1		3*3		  72	double arry
	E2		3*3		  72	double arry
Grand total is 72 elements uisng 576 bytes
>>what
M-files in the current disrectory d:\Program Files\MATLAB71\work
cplxmap    intexp3    m4simu13    optfun    updown1
flow1		m4_simu14	mysource	tmps	updown2
MEX-files in the current directory d:\Program File\MATLAB71\work
fact		myclac
MDL-files in the current directory d:\Program File\MATLAB71\work
signa9		simu3
signa10		simu4
simu1		simu5
simu11		simu6
simu12		simu7
simu13		simu8
simu13_state_space		simu_15
simu14_transfer_function simu_continuous0
simu14_nonliner 	simu_continuousl
simu2
>>clear

Display of command window

Format commandmeaning
format shortIncluding 4 significant digits after the decimal point, and no more than 7 significant digits at most; If the value is greater than 1000, it is expressed according to the scientific counting method
format longRepresented by 15 digits
format short e5-digit scientific counting method
format long e15 bit scientific calculation method
foramt short gAutomatically select the best numerical representation from format short and format short e
format long gAutomatically select the best numerical representation from format long and format long e
format ratIt is expressed by approximate rational numbers
format hexHexadecimal representation
format +It is used for +, - and spaces to represent positive, negative and zero respectively. Imaginary numbers in complex numbers are not represented
format bankFinancial representation, yuan, angle, grade
format compartThere are no spaces between display variables
format looseSpace between display variables

Keywords: Programming MATLAB

Added by ukalpa on Sun, 16 Jan 2022 04:05:51 +0200