正在加载图片...
Variables 7 Try to create the following variables by typing them after the npt fol. lowed by Enter:N-friends-12,SaDay-60.3rd_classified-11.What hap- pens,and why?MATLAB gives you the following error: ??SaDay=60 Error:The input character is not valid in MATIAB statements or expressions. Obviously.in these examples we didn't follow the aforementioned rules(use of the nd s er MATLAB ha variable names.Some of these are presented in MATLAb answer Value contained in the variable ans=3.1416 ans=2.2204e-016 Floating-point double-precision number =0+1.00001 (-1).used to ans=0+1.0000 ans NaN Not a number Inf ans=inf Infinity You can redefine a variable by simply assigning it a new value: >pi=12 KENTER> pi -12 >pi <ENTER> -12 Once you have insertedanew value.you cannot recall the previous one.Ho weve the predefined variable is restored.To clear variables you use the command clear followed by the variable name (or a list of them).Let's try: >clear pi <ENTER> MATLAB doesn't give you an answer.However,the command has been executed. Type the pi variable again,and MATLAB will return the value of >>pi ans 3.1416 Variables 7 Try to create the following variables by typing them after the >> prompt fol￾lowed by Enter: N-friends = 12 , $aDay = 60 , 3rd_classified = 11 . What hap￾pens, and why? MATLAB gives you the following error: ??? $aDay=60 | Error: The input character is not valid in MATLAB statements or expressions. Obviously, in these examples we didn’t follow the aforementioned rules (use of the character—and $, beginning the name with a number). MATLAB has a few predefi ned variable names. Some of these are presented in the following table: To TYPE after prompt >> followed by Enter MATLAB answer Value contained in the variable Pi ans= 3.1416 p Esp ans= 2.2204e-016 Floating-point relative accuracy, i.e., the distance from 1.0 to the next largest double-precision number j ans= 0+ 1.0000i Imaginary unit, i.e., sqrt(−1), used to enter complex numbers I ans= 0+ 1.0000i Imaginary unit, i.e., sqrt(−1), used to enter complex numbers NaN ans= NaN Not a number Inf ans= inf Infi nity You can redefi ne a variable by simply assigning it a new value: >> pi=12 <ENTER> pi = -12 >> pi <ENTER> pi = -12 Once you have inserted a new value, you cannot recall the previous one. However, in the special case of predefi ned variables, you can clear the redefi ned variable, and the predefi ned variable is restored. To clear variables you use the command clear followed by the variable name (or a list of them). Let’s try: >> clear pi <ENTER> MATLAB doesn’t give you an answer. However, the command has been executed. Type the pi variable again, and MATLAB will return the value of p : >> pi <ENTER> ans = 3.1416
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有