正在加载图片...
Thinking in a Matrix Way 13 1 3 91 1215 Now type: >1=2;j=4: <ENTER> >×(1:j,2) <ENTER> ans Note that more than one command has been typed on the first line.This can be done by separating commands with a semicolon.In addition,note that MATLAB displays exactly the values from the second row to the fourth row in the second columns.This is equivalent to: >x([234],2) <ENTER> ans 5 8 11 As a matter of fact,using the colon operator is equivalent to generating a vector going from a given value to another one,possible using a prescribed increment (step).The rule is: Start:Step:Stop Type the following commands: To TYPE after prompt >>followed by Enter MATLAB answer Meaning of the operation 2525 ans Generate a vector going from 2 to 25 27121722 which isgr er tha exceeds the Stop value (i.e.5 i:j 234 MATLAB uses the default value l 10:-3:-5 ans Generate a vector going from 10 to-5. 10741-2-5 increasing the first value by-5.This is quivalent to generating a vector of decreasing values Thinking in a Matrix Way 13 x = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Now type: >> i=2; j=4; <ENTER> >> x(i:j,2) <ENTER> ans = 5 8 11 Note that more than one command has been typed on the fi rst line. This can be done by separating commands with a semicolon. In addition, note that MATLAB displays exactly the values from the second row to the fourth row in the second columns. This is equivalent to: >> x([2 3 4],2) <ENTER> ans = 5 8 11 As a matter of fact, using the colon operator is equivalent to generating a vector going from a given value to another one, possible using a prescribed increment (step). The rule is: Start:Step:Stop Type the following commands: To TYPE after prompt >> followed by Enter MATLAB answer Meaning of the operation 2:5:25 ans = 2 7 12 17 22 Generate a vector going from 2 to 25 incremented by 5. Note that 22 + 5 = 27, which is greater than 25. MATLAB will generate numbers until it reaches or exceeds the Stop value (i.e., 25) i:j ans = 2 3 4 Generate a vector going from 2 to 4. Here the step value is not specifi ed, and MATLAB uses the default value 1 10:−3:−5 ans = 10 7 4 1 -2 -5 Generate a vector going from 10 to −5, increasing the fi rst value by −5. This is equivalent to generating a vector of decreasing values
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有