正在加载图片...
Variables 5 We conclude by giving some hints on creating and editing command lines You can select(and edit)previous commands you have entered using the up- arrow and down-arrow keys.Remember to press Enter to execute the command. MATLAB has a useful editing feature called smart recall.Just type the first few characters of the command you want to recall,e.g.,type the characters 1o and mmand starting with 1o. Variables Thus far,we have seen the use of MATLAB as a scientific calculator.However, MATLAB is much more than a calculator,and the main difference is the possibility to use"variables."In a scientific calculator we can save and recall a single numbe only.In MATLAB.in ast (as in othe r program ming lan ges) es calle obo的ndmeo,b of differen naming it.In such a box you can put the(virtual)item you need,for example a number,an image, and so on. Suppose you want to save a number representing your age.You can create your own variable and store it by simply typing the following command: <ENTER> 22 The symbol age is the variable name(the box name),which contains the numbe 22.Each time you recall(type)such a name,the content of the variable is used;in this simple case,it is displayed.Type again the variable name: >age <ENTER> age= 22 You can define other variables,for example the number of your friends.Just type >Nfriends 132 <ENTER> Nfriends■ 132 Variables 5 We conclude by giving some hints on creating and editing command lines: • You can select (and edit) previous commands you have entered using the up￾arrow and down-arrow keys. Remember to press Enter to execute the command. • MATLAB has a useful editing feature called smart recall . Just type the fi rst few characters of the command you want to recall, e.g., type the characters lo and press the up-arrow key—this recalls the most recent command starting with lo . The result might be, for example, log(10) or log10(12). Variables Thus far, we have seen the use of MATLAB as a scientifi c calculator. However, MATLAB is much more than a calculator, and the main difference is the possibility to use “variables.” In a scientifi c calculator we can save and recall a single number only. In MATLAB, in contrast (as in other programming languages), we can store and recall virtually an infi nity of different values called variables . A variable is a sort of box, having a certain shape, a certain dimension, with a label naming it. In such a box you can put the (virtual) item you need, for example a number, an image, and so on. Suppose you want to save a number representing your age. You can create your own variable and store it by simply typing the following command: >> age=22 <ENTER> age = 22 The symbol age is the variable name (the box name), which contains the number 22. Each time you recall (type) such a name, the content of the variable is used; in this simple case, it is displayed. Type again the variable name: >> age <ENTER> age= 22 You can defi ne other variables, for example the number of your friends. Just type: >> Nfriends = 132 <ENTER> Nfriends = 132
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有