v=linspace(-4,25,20); v1=-4:3.79:25 v1 = Columns 1 through 5 -4.0000 -0.2100 3.5800 7.3700 11.1600 Columns 6 through 8 14.9500 18.7400 22.5300 m=1:4; M=[m;m;m;m] M = 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 n=1:3:10; N=[n',(n*2)', (n*3)'] N = 1 2 3 4 8 12 7 14 21 10 20 30 v=1:4; v v = 1 2 3 4 5*v ans = 5 10 15 20 v*5 ans = 5 10 15 20 v-4 ans = -3 -2 -1 0 4-v ans = 3 2 1 0 v/3 ans = 0.3333 0.6667 1.0000 1.3333 3/v {Error using / Matrix dimensions must agree. } v^2 {Error using ^ Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead. } v1=1:3; v+v1 {Error using + Matrix dimensions must agree. } v1=10:14; v+v1 {Error using + Matrix dimensions must agree. } v1=10:13; v+v1 ans = 11 13 15 17 v1-v ans = 9 9 9 9 v*v1 {Error using * Inner matrix dimensions must agree. } v*v1' ans = 120 v'*v1 ans = 10 11 12 13 20 22 24 26 30 33 36 39 40 44 48 52 M M = 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 5*M ans = 5 10 15 20 5 10 15 20 5 10 15 20 5 10 15 20 M*5 ans = 5 10 15 20 5 10 15 20 5 10 15 20 5 10 15 20 M/5 ans = 0.2000 0.4000 0.6000 0.8000 0.2000 0.4000 0.6000 0.8000 0.2000 0.4000 0.6000 0.8000 0.2000 0.4000 0.6000 0.8000 5/M {Error using / Matrix dimensions must agree. } M M = 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 M*v {Error using * Inner matrix dimensions must agree. } v*M ans = 10 20 30 40 M*v' ans = 30 30 30 30 M5=m*5; M5=M*5; M M = 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 M5 M5 = 5 10 15 20 5 10 15 20 5 10 15 20 5 10 15 20 M+M5 ans = 6 12 18 24 6 12 18 24 6 12 18 24 6 12 18 24 M5-M ans = 4 8 12 16 4 8 12 16 4 8 12 16 4 8 12 16 M*M ans = 10 20 30 40 10 20 30 40 10 20 30 40 10 20 30 40 M/M5 [Warning: Matrix is singular to working precision.] ans = NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN M/M [Warning: Matrix is singular to working precision.] ans = NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN B=magic(4) B = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 B/B [Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.306145e-17.] ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 5.+6 ans = 11 a=5; a.+4 a.+4 | {Error: Unexpected MATLAB operator. } v*v1 {Error using * Inner matrix dimensions must agree. } v.*v1 ans = 10 22 36 52 v v = 1 2 3 4 v1 v1 = 10 11 12 13 v^2 {Error using ^ Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead. } v.^2 ans = 1 4 9 16 v/v ans = 1.0000 v/v1 ans = 0.2247 v./v1 ans = 0.1000 0.1818 0.2500 0.3077 c=(v./v1)*10 c = 1.0000 1.8182 2.5000 3.0769 help round round - Round to nearest integer This MATLAB function rounds the elements of X to the nearest integers. Y = round(X) Reference page for round See also ceil, fix, floor Other functions named round fixedpoint/round round(c) ans = 1 2 3 3 c c = 1.0000 1.8182 2.5000 3.0769 c=[1.5 2.89 1.2 -3.5 -2.6 -2.1 ] c = Columns 1 through 5 1.5000 2.8900 1.2000 -3.5000 -2.6000 Column 6 -2.1000 round(c) ans = 2 3 1 -4 -3 -2 ceil(c) ans = 2 3 2 -3 -2 -2 c c = Columns 1 through 5 1.5000 2.8900 1.2000 -3.5000 -2.6000 Column 6 -2.1000 floor(c) ans = 1 2 1 -4 -3 -3 c c = Columns 1 through 5 1.5000 2.8900 1.2000 -3.5000 -2.6000 Column 6 -2.1000 fix(c) ans = 1 2 1 -3 -2 -2 c c = Columns 1 through 5 1.5000 2.8900 1.2000 -3.5000 -2.6000 Column 6 -2.1000 s=759.47 s = 759.4700 (round(s/10))*10 ans = 760 round(s/10)*10 ans = 760 round(s*10)/10 ans = 759.5000 v1 v1 = 10 11 12 13 v(2) ans = 2 v1(2) ans = 11 v1(4/2) ans = 11 v1(4/3) {Subscript indices must either be real positive integers or logicals. } v1(fix(4/3)) ans = 10 v1(1+3-2) ans = 11 V1([1 3]) {Undefined function 'V1' for input arguments of type 'double'. } v1([1 3]) ans = 10 12 v1(5) {Index exceeds matrix dimensions. } v1(1 3) v1(1 3) | {Error: Unexpected MATLAB expression. } v1(2:4) ans = 11 12 13 v1([2:4]) ans = 11 12 13 v1([1:3 2:4]) ans = 10 11 12 11 12 13 v1(1:3 2:4) v1(1:3 2:4) | {Error: Unexpected MATLAB expression. } v1(3:-1:1) ans = 12 11 10 v1(2:end) ans = 11 12 13 v1(:) ans = 10 11 12 13 M M = 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 M=M*5 M = 5 10 15 20 5 10 15 20 5 10 15 20 5 10 15 20 M(2,3) ans = 15 M([1 3],4/2) ans = 10 10 M([1 3],1:3) ans = 5 10 15 5 10 15 M([1 3],end) ans = 20 20 M([1 3],:) ans = 5 10 15 20 5 10 15 20 M(:,:) ans = 5 10 15 20 5 10 15 20 5 10 15 20 5 10 15 20 M=[1 2 3;4 5 6;7 8 9] M = 1 2 3 4 5 6 7 8 9 M(3) ans = 7 M(7) ans = 3 M(:) ans = 1 4 7 2 5 8 3 6 9 diary off