disp('hello there'); hello there disp('hello there!$'); hello there!$ disp('don't forget class ends at 4:35'); disp('don't forget class ends at 4:35'); | {Error: Unexpected MATLAB expression. } disp('don''t forget class ends at 4:35'); don't forget class ends at 4:35 input('give me a number') give me a number5 ans = 5 input('give me a number ') give me a number 6 ans = 6 a = input('give me a number ') give me a number 7 a = 7 a = input('give me a number '); give me a number 8 disp(a) 8 a = input('give me a number ', 's'); give me a number hello disp(a) hello b = input('give me a number '); give me a number hello {Attempt to execute SCRIPT hello as a function: /Users/mweeks/Documents/MATLAB/hello.m } give me a number a disp(a) hello disp(b) hello b = input('give me a number ','s'); give me a number a disp(b) a b = input('give me a number '); give me a number 17.3 disp(b) 17.3000 c = input('give me a number '); give me a number 9 whos Name Size Bytes Class Attributes a 1x5 10 char ans 1x1 8 double b 1x1 8 double c 1x1 8 double disp(c) 9 d = uint8(9) d = 9 whos Name Size Bytes Class Attributes a 1x5 10 char ans 1x1 8 double b 1x1 8 double c 1x1 8 double d 1x1 1 uint8 disp(sprintf('hello %s you are %d years old', a, c)) hello hello you are 9 years old example_switch a is less than b four ??? a is unknown value three four five six or seven five six or seven five six or seven ??? a is unknown value a less a 6 b 5 c 8 a between b and c cos(4) ans = -0.6536 help cos cos Cosine of argument in radians. cos(X) is the cosine of the elements of X. See also acos, cosd. Overloaded methods: codistributed/cos gpuArray/cos sym/cos Reference page in Help browser doc cos cos(4,5) {Error using cos Too many input arguments. } cos(5) ans = 0.2837 edit exfun.m help exfun exfun.m This is an example function. With an integer parameter, return a 0 if it is even, or 1 if it is odd. -MCW Usage: exfun(5) exfun(5) ans = 1 exfun(6) ans = 1 exfun(7) ans = 1 exfun(8) ans = 1 help od od not found. Use the Help browser search field to search the documentation, or type "help help" for help command options, such as help for methods. help mod mod Modulus after division. mod(x,y) is x - n.*y where n = floor(x./y) if y ~= 0. If y is not an integer and the quotient x./y is within roundoff error of an integer, then n is that integer. The inputs x and y must be real arrays of the same size, or real scalars. The statement "x and y are congruent mod m" means mod(x,m) == mod(y,m). By convention: mod(x,0) is x. mod(x,x) is 0. mod(x,y), for x~=y and y~=0, has the same sign as y. Note: REM(x,y), for x~=y and y~=0, has the same sign as x. mod(x,y) and REM(x,y) are equal if x and y have the same sign, but differ by y if x and y have different signs. See also rem. Overloaded methods: codistributed/mod gpuArray/mod sym/mod Reference page in Help browser doc mod mod(9,3) ans = 0 mod(10,3) ans = 1 mod(10,2) ans = 0 mod(11,2) ans = 1 mod(12,2) ans = 0 mod(13,2) ans = 1 clc exfun(1) ans = 1 exfun(2) ans = 0 exfun(3) ans = 1 exfun(4) ans = 0 type exfun.m % exfun.m % % This is an example function. % With an integer parameter, return a 0 if it is even, % or 1 if it is odd. % -MCW % % Usage: % exfun(5) function rval = exfun(in) rval = mod(in, 2); type exfun.m % exfun.m % % This is an example function. % With an integer parameter, return a 0 if it is even, % or 1 if it is odd. % -MCW % % Usage: % exfun(5) %function rval = exfun(in) function exfun(in) rval = mod(in, 2); exfun(4) exfun(5) disp(exfun(5)) {Error using exfun Too many output arguments. } type exfun.m % exfun.m % % This is an example function. % With an integer parameter, return a 0 if it is even, % or 1 if it is odd. % -MCW % % Usage: % exfun(5) function rval = exfun(in) rval = mod(in, 2); exfun(5) ans = 1 exfun(5) ans = 1 exfun(4) ans = 0 exfun(3) ans = 1 exfun(2) ans = 0 exfun(2.6) ans = 1 f = 0.1 f = 0.1000 disp(sprintf('%tx', f)) 3dcccccd if (sqrt(7^2) == 7) disp('equal'); else disp('unequal'); end equal if (sqrt(7)^2 == 7) disp('equal'); else disp('unequal'); end unequal sqrt(7)^2 ans = 7.0000 fomrat long {Undefined function 'fomrat' for input arguments of type 'char'. } format long sqrt(7)^2 ans = 7.000000000000001 clc exfun(11) ans = 1 exfun(-11) ans = 1 exfun(-10) ans = 0 exfun(0) ans = 0 exfun(1j) ans = 1 exfun(i) ans = 1 disp(i) 0.000000000000000 + 1.000000000000000i exfun(1+i) ans = 1 exfun(2+i) ans = 1 exfun(2+2i) ans = 0 exfun(1+2i) ans = 1 real(1+2i) ans = 1 real(4+2i) ans = 4 real(6+2i) ans = 6 real(5+2i) ans = 5 real(5+i) ans = 5 exfun(3.9) ans = 1 exfun(3.9999999999999999) ans = 0 exfun(3.9999999999999) ans = 1 exfun(3.99999999999999) ans = 1 exfun(3.9999999999999999) ans = 0 exfun(3.999999999999999) ans = 1 exfun(3.9999999999999994) ans = 1 exfun(-3.9999999999999994) ans = 1 exfun(-3.99999999999999999) ans = 0 exfun('$') ans = 0 exfun(-'$') ans = 0 exfun(' ') ans = 0 exfun('!') ans = 1 exfun('"') ans = 0 exfun('#') ans = 1 floor(3.1) ans = 3 floor(-3.1) ans = -4 ceil(3.1) ans = 4 ceil(-3.1) ans = -3 round(3.1) ans = 3 round(3.6) ans = 4 integer(3.1) {Undefined function 'integer' for input arguments of type 'double'. } int(3.1) {Undefined function 'int' for input arguments of type 'double'. } int16(3.1) ans = 3 int16(-3.1) ans = -3 exfun2(4) ans = 0 help exfun2 exfun2.m This is another example function. Returns both the sin and cos of the input. -MCW Usage: [sinval, cosval] = exfun2(5) [sinval, cosval] = exfun2(5) sinval = -0.958924274663138 cosval = 0.283662185463226 help exfun3 exfun3.m This is another example function. multiple inputs -MCW Usage: out = exfun3(sinval, cosval) a = exfun3(sinval, cosval) a = 16.927989444555315 a = exfun3(sinval, 0) a = 17.199999999999999 a = exfun4(sinval, 0) {Error: File: exfun4.m Line: 10 Column: 15 Expression or statement is incorrect--possibly unbalanced (, {, or [. } [a,b] = exfun4(sinval, 0) {Error: File: exfun4.m Line: 10 Column: 15 Expression or statement is incorrect--possibly unbalanced (, {, or [. } [a,b] = exfun4(sinval, 0) a = 17.199999999999999 b = 4.171340851085623 c = [1 3 5 7] c = 1 3 5 7 c = [1 +3 5 7] c = 1 3 5 7 c = [1 + 3 5 7] c = 4 5 7 c = [1 +3j 5 7] c = Column 1 1.000000000000000 + 0.000000000000000i Column 2 0.000000000000000 + 3.000000000000000i Column 3 5.000000000000000 + 0.000000000000000i Column 4 7.000000000000000 + 0.000000000000000i c = [1 + 3j 5 7] c = Column 1 1.000000000000000 + 3.000000000000000i Column 2 5.000000000000000 + 0.000000000000000i Column 3 7.000000000000000 + 0.000000000000000i c = [1 + 3j, 5, 7] c = Column 1 1.000000000000000 + 3.000000000000000i Column 2 5.000000000000000 + 0.000000000000000i Column 3 7.000000000000000 + 0.000000000000000i whos Name Size Bytes Class Attributes a 1x1 8 double ans 1x1 8 double b 1x1 8 double c 1x3 48 double complex cosval 1x1 8 double d 1x1 1 uint8 f 1x1 8 double sinval 1x1 8 double [a,b] = exfun4(sinval, 0) Name Size Bytes Class Attributes c 1x1 8 double out1 1x1 8 double out2 1x1 8 double s 1x1 8 double a = 17.199999999999999 b = 4.171340851085623 type exfun4.m % exfun4.m % % This is another example function. % multiple inputs, multiple outputs % -MCW % % Usage: % [out1, out2] = exfun4(sinval, cosval) function [out1, out2] = exfun4(s, c) out1 = s * c + 17.2; out2 = (c - 4) / s; val3 = 31; whos [a,b] = exfun4(sinval, 0) Name Size Bytes Class Attributes c 1x1 8 double out1 1x1 8 double out2 1x1 8 double s 1x1 8 double val3 1x1 8 double a = 17.199999999999999 b = 4.171340851085623 whos Name Size Bytes Class Attributes a 1x1 8 double ans 1x1 8 double b 1x1 8 double c 1x3 48 double complex cosval 1x1 8 double d 1x1 1 uint8 f 1x1 8 double sinval 1x1 8 double example_switch a is less than b four ??? a is unknown value three four five six or seven five six or seven five six or seven ??? a is unknown value a less a 6 b 5 c 8 a between b and c whos Name Size Bytes Class Attributes a 1x1 8 double ans 1x1 8 double b 1x1 8 double c 1x1 8 double cosval 1x1 8 double d 1x1 1 uint8 f 1x1 8 double sinval 1x1 8 double clear whos example_switch a is less than b four ??? a is unknown value three four five six or seven five six or seven five six or seven ??? a is unknown value a less a 6 b 5 c 8 a between b and c whos Name Size Bytes Class Attributes a 1x1 8 double b 1x1 8 double c 1x1 8 double type script1.m % script1.m % f = a * 4; disp(f); clear whos script1 {Undefined function or variable 'a'. Error in script1 (line 5) f = a * 4; } a = 7 a = 7 script1 28 script1 28 Name Size Bytes Class Attributes a 1x1 8 double f 1x1 8 double whos Name Size Bytes Class Attributes a 1x1 8 double f 1x1 8 double [a,b] = exfun4(sinval, 0) {Undefined function or variable 'sinval'. } [a,b] = exfun4(0.3, 0) {Undefined function or variable 'a'. Error in exfun4 (line 14) val2 = a } out1 {Undefined function or variable 'out1'. } s = 0.3 s = 0.300000000000000 c = 0; exfun4 val2 = 7 Name Size Bytes Class Attributes a 1x1 8 double c 1x1 8 double f 1x1 8 double out1 1x1 8 double out2 1x1 8 double s 1x1 8 double val2 1x1 8 double val3 1x1 8 double exfun4 {Undefined function or variable 'idontexist'. Error in exfun4 (line 14) val2 = idontexist } out1 out1 = 17.199999999999999 out2 out2 = -13.333333333333334 clear clc type exfun4.m % exfun4.m % % This is another example function. % multiple inputs, multiple outputs % -MCW % % Usage: % [out1, out2] = exfun4(sinval, cosval) %function [out1, out2] = exfun4(s, c) out1 = s * c + 17.2; out2 = (c - 4) / s; val2 = idontexist val3 = 31; whos c = 0; s = 0.3 s = 0.300000000000000 exfun4 {Undefined function or variable 'idontexist'. Error in exfun4 (line 14) val2 = idontexist } whos Name Size Bytes Class Attributes c 1x1 8 double out1 1x1 8 double out2 1x1 8 double s 1x1 8 double [a,b] = exfun4(0.3, 0) Name Size Bytes Class Attributes c 1x1 8 double out1 1x1 8 double out2 1x1 8 double s 1x1 8 double val3 1x1 8 double a = 17.199999999999999 b = -13.333333333333334 % we talked about functions versus scripts % modular % scope diary off