正在加载图片...
14 I Basic Operation You now have three equivalent ways of accessing the third-row entries of x: >×(3,[1231) <ENTER> ans 9 >x(3,1:3) <ENTER> ans 789 >x(3,:) <ENTER> ans 789 In the last case ecify the start and stop values when you use if you need the first column only,you can type either x([1,2,3,4,51,1)or x([1:5],1)0r×(:,1); By using the colon operator together with the empty array,we are able to delete entire rows or entire columns.For example,to delete the entire second column of x and then its third and fourth rows,type: <ENTER> 1 47 10 12 1315 >×([3,4],:)=【1 <ENTER> X 3 g 15 Note that you cannot delete a single entry in a matrix because that would lead to an ambiguity in its dimensions.So a statement like x(1,2)=[I returns an error: >×(1,2)=[1 ??Subscripted assignment dimension mismatch. We conclude this paragraph by mentioning a way to create a matrix using index ing.In contrast to。 we do eed to cll to MATLAB is,ete.)before using it.MATLAB t type able,how large i B creates the variable on the fly.So if you want to insert the response time to the stimulus number 10.you can simply type: >AnsTime(10)=1.34 AnsTime 0 0 0 000. 0 0 01.340014 1 Basic Operations You now have three equivalent ways of accessing the third-row entries of x: >> x(3,[1 2 3]) <ENTER> ans = 7 8 9 >> x(3,1:3) <ENTER> ans = 7 8 9 >> x(3,:) <ENTER> ans = 7 8 9 In the last case, you do not need to specify the start and stop values when you use the colon operator. MATLAB assumes that you mean the entire row. Analogously, if you need the fi rst column only, you can type either x([1,2,3,4,5],1) or x([1:5],1) or x(:,1); By using the colon operator together with the empty array, we are able to delete entire rows or entire columns. For example, to delete the entire second column of x and then its third and fourth rows, type: >> x(:,2) = [ ] <ENTER> x = 1 3 4 6 7 9 10 12 13 15 >> x([3,4],:) =[ ] <ENTER> x = 1 3 4 6 13 15 Note that you cannot delete a single entry in a matrix because that would lead to an ambiguity in its dimensions. So a statement like x(1,2)=[ ] returns an error: >> x(1,2)=[ ] ??? Subscripted assignment dimension mismatch. We conclude this paragraph by mentioning a way to create a matrix using index￾ing. In contrast to other computer languages, in MATLAB we do not need to declare a variable (i.e., tell to MATLAB what type of variable, how large it is, etc.) before using it. MATLAB creates the variable on the fl y. So if you want to insert the response time to the stimulus number 10, you can simply type : >> AnsTime(10)=1.34 AnsTime = 0 0 0 0 0 0 0 0 0 1.3400
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有