当前位置:网站首页>Matlab learning and actual combat notes

Matlab learning and actual combat notes

2022-07-06 11:46:00 @Little snail

Brief notes


1、

str=‘ With a semicolon ; ending , Don't show this sentence ’;
str_show=‘ No semicolon ; ending , Then the current variable content is displayed ’

This is a MATLAB A feature of , If a sentence is semicolon ‘;’ ending , Then the corresponding content or running result of this statement will not be displayed in the command window , If there is no semicolon ‘;’ Will be displayed . Be careful >> Together with the flashing cursor, it indicates that the system is ready , Waiting for input .

2、
The above is a small example of command line development , Other noteworthy places are
In the command window Enter Key submit command execution ,Shift+Enter You can continue to enter commands .
Operator used ( Such as +、-、^ etc. ) It is common in various calculation programs .
You can type an expression directly ( Such as 1+2), In the calculation results ans It's English “answer” An abbreviation for , Its meaning is “ Arithmetic answer ”.ans yes Matlab A predefined variable of .

3、MATLAB Built in output function disp(X)
disp The function is MATLAB Built in output function , Directly calling it can output the results you want in the command window X. there X It can be all kinds of data , Including digital 、 character 、 Matrices and so on . This level only needs to output a string of characters , for instance , For example, in the creation of test.m Enter the following code in the file :

4、 Character type data is in English single quotation marks ’ ‘ To represent the ! Like in the example ’ Hello !’

5、 Percent sign % Notation , in other words % The following content does not participate in the execution of the program , It is only used as an explanation of the sentence

6、 Variable naming rule
Variable name 、 Function names are case sensitive . Such as myVar And myvar Two Different variables .
The first letter of the variable name Must be English letters .
Variable names can contain English letters 、 Underline and numbers .
Variable name You can't Include spaces 、 punctuation .
The variable name can contain at most 63 Characters (6.5 And later versions ).

7、MATLAB use “\” and ”/” respectively “ be demoted ” and “ Divide right ”. For scalars , There is no difference between the two . Have different effects on the matrix .

8、 Common functions

disp(X): Used to display variables X Value , And the variable name is not displayed X
num2str(A): Used to convert numbers A Convert to string , According to the structure of this function, it is easy to see its meaning “number to string”, Isn't it very interesting
in addition , There are many, many useful functions , I won't give you too much introduction here , The following levels will be introduced slowly .
input(): It is used for users to input data in the program , The specific usage is x = input(prompt) perhaps str = input(prompt,‘s’), The former means entering a value , The latter means entering a string . When the program runs to this place , In the command window , The user needs to input a data , End with enter , Then this data will be stored in x( If character input is used , Is stored in str), among ,prompt Indicates a hint , It's usually a string , And this string must have ( Can be an empty string "").

原网站

版权声明
本文为[@Little snail]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060913091237.html