Matlab Workshop Getting Started
Command Window Editor
Matlab As A Really Fancy Calculator In the command window enter the following: 1+2
Matlab As A Really Fancy Calculator In the command window enter the following: 1+2
Addition In the command window enter the following: 1+2+3
Subtraction In the command window enter the following: 5-3
Multiplication In the command window enter the following: 4*6
Division In the command window enter the following: 15/3
Exponents In the command window enter the following: 2^3
Brackets In the command window enter the following: Now try: 1+2*3 (1+2)*3 Evaluated first Evaluated first
Matrices In the command window enter the following: [1 2; 3 4]
Matrix Multiplication In the command window enter the following: [1 2; 3 4]*[2 1; 3 4]
Pointwise Multiplication In the command window enter the following: [1 2; 3 4].*[2 1; 3 4] “Point-wise multiplication”
Matrix Division In the command window enter the following: [1 2; 3 4]/[2 1; 3 4]
Point-wise Matrix Division In the command window enter the following: [3 8; 15 24]./[3 4; 5 6] “Point-wise division”
Trigonometry In the command window enter the following: sin(1.57) cos(1.047)
Trigonometry In the command window enter the following: tan(0.7854)
Trigonometry In the command window enter the following: asin(0.4794) acos(0.8776) atan(0.2553)
Variable Assignment In the command window enter the following: This creates a variable called “a” and assigns it a value of 2.
Variable Assignment Q: Why did it say a = 2 after I hit enter? A: Because if you don’t end the line with “;” then Matlab prints out the result of your operation.
Suppressing Output b = 3;
Suppressing Output b = 3; No extra output!
Let’s make another variable c = 5;
Now We Can Do Math With Our Variables In the command window enter the following: a+b b*c a+b*c
Variable Types a = 2; b = 2.75; Integer Rational Number
Variable Types c = ‘z’; d = ‘hello’; Character String
Variable Types e = [2 3]; f = {3,2}; Array Cell Array
Variable Types h = [2 1; 3 4]; Matrix
Variable Types g.Name = 'Me'; g.Age = 28; Structure Array
Indexing Each variable type has a particular indexing syntax: h(2,1) % Matrices are indexed by row and then column a(1) % Integers are special cases of matrices b(1) % So are rational numbers c(1) % So are characters d(2) % So are strings e(2) % So are arrays f{2} % Cells are indexed using curly braces g.Name % Struct arrays are indexed using the "." notation
Indexing Each variable type has a particular indexing syntax: h(2,1) % Matrices are indexed by row and then column a(1) % Integers are special cases of matrices b(1) % So are rational numbers c(1) % So are characters d(2) % So are strings e(2) % So are arrays f{2} % Cells are indexed using curly braces g.Name % Struct arrays are indexed using the "." notation
Math With Variables a+b a-b a*b a/b sin(a) cos(a) tan(a) log(a) exp(a) h*h h.*h h/h