●矩阵的排序:sortrows >matls=sortrows(mat1,1) >mat1s=sortrows(mat1) matls 0 1 0 0 1 0 1 g 54 3 2 1 5 2 1 5 7 9 0 7 9 0 >>help sortrovs SORTROWS Sort rows in ascending order. Y SORTROWS(X)sorts the rows of the matrix X in ascending order as a 类似excel中的排序 group.X is a 2-D numeric or char matrix.For a char matrix containing strings in each row,this is the familiar dictionary sort.When X is complex,the elements are sorted by ABS(X).Complex matches are further >at1=[1543:215:790:010] sorted by ANGLE(X).X can be any numeric or char class.Y is the same size and class as X. matl= SORIROWS (X,COL)sorts the matrix based on the columns specified in the vector COL.If an element of CoL is positive,the corresponding column 1 54 0 in X will be sorted in ascending order:if an element of CoL is negative, the corresponding column in X will be sorted in descending order.For 7 9 0 example,SORIROWS(X,[2 -3])sorts the rows of X first in ascending order 0 0 for the second column,and then by descending order for the third column
⚫ 矩阵的排序: sortrows 类似excel中的排序
●矩阵拼接:horzcat,vertcat 矩阵重复:repmat ● >mat3=[101:111:000:010] mat3 0 1 0 0 0 0 1 0 >mat13=horcat(mat1,mat3) ??Undefined function or method 'horcat'for input arguments of type 'double'. >mat13=horzcat(matl,mat3) mat13 1 54 3 1 0 1 2 1 5 1 1 1 9 0 0 0 0 0 1 0 0 1 0 >>mat111=repmat(mat1,1,3) >mat13=vertcat(matl,mat3) mat111 mat13 54 3 1 54 3 1 54 3 2 1 64 3 2 1 5 2 1 5 5 7 9 0 7 9 0 7 9 0 9 0 0 0 0 0 0 0 0
⚫ 矩阵拼接:horzcat, vertcat ⚫ 矩阵重复:repmat
3.2加减运算 ·两个矩阵的大小必须相同才能相加减 >vect1+3 >vect1+vect1 vect1+vect2 ans 457 9 6 ans >vect2-3 2 8 12 6 ans ??Error using=>plus Matrix dimensions must agree. -2 -1 3 0
⚫ 两个矩阵的大小必须相同才能相加减
>>2*3 2/3 3.3数量的乘除运算 vect1*3 vect1/2 mat1*0.5 。数量的乘除直接用*和/ ans ans 0.6667 ans 361218 ans 0.50001.0000 2.00003.0000 1.5000 ans 0.5000 27.0000 1.5000 1.0000 0.5000 2.5000 3.5000 4.5000 0 0 0.5000 0
⚫ 数量的乘除直接用*和/
>3+1*4 3*4+1 ·乘除优先于加减 (3+1)*4 ●先算加减的话要用()括起来 ans 7 ans 13 ans 16
⚫ 乘除优先于加减 ⚫先算加减的话要用()括起来