正在加载图片...
10 I Basic Operations Sometimes we need to know the size of the variables only,instead of the full list of their properties.In this case.the function size(c)returns the number of rows and columns of the variable >>size(c) ans 43 Another useful function is length(c),which returns the length of the vector c. If cis a matrix,the function length returns the number of rows only: >>length(c) ans- To put data into a matrix.you must type the values within square brackets.sepa rated by spaces or commas for different elements in a row,while the semicolon (: is used to indicate the end of the row.Note that the number of elements must be the same in each row: >x=[123:2571 <ENTER> x 1 2 5 7 If you have not put the same number of elements in each row,MATLAB displays an error: >>X=「23:2571: ??Error using ==vertcat CAT arguments dimensions are not consistent As you can see,MATLAB is not a wizard who tries putting the missing element place.MATLAB does not know whethe first and second respectively. You can use a matrix or a vector to implement another variable.For example, type in the following statements: >>×=[321]: <ENTER> >y=[6,7,81: <ENTER> <ENTER> KENTER>10 1 Basic Operations Sometimes we need to know the size of the variables only, instead of the full list of their properties. In this case, the function size(c) returns the number of rows and columns of the variable c : >> size(c) ans = 4 3 Another useful function is length(c), which returns the length of the vector c . If c is a matrix, the function length returns the number of rows only: >> length(c) ans= 4 To put data into a matrix, you must type the values within square brackets, sepa￾rated by spaces or commas for different elements in a row, while the semicolon (;) is used to indicate the end of the row. Note that the number of elements must be the same in each row: >> x=[ 1 2 3; 2 5 7] <ENTER> x = 1 2 3 2 5 7 If you have not put the same number of elements in each row, MATLAB displays an error: >> x = [2 3; 2 5 7]; ??? Error using ==> vertcat CAT arguments dimensions are not consistent. As you can see, MATLAB is not a wizard who tries putting the missing element in the right place. MATLAB does not know whether you want to put the element 2 and 3 in the fi rst and second columns or in the second and third columns respectively. You can use a matrix or a vector to implement another variable. For example, type in the following statements: >> x = [3 2 1]; <ENTER> >> y = [6,7,8]; <ENTER> >> z1 = [x -y]; <ENTER> >> z2 = [x; -y]; <ENTER>
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有