1/52
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
For loop
Execute a specific number of times
While loop
Executes until a specific condition is met
Example of while loop
While k<=5
k=k+1
End
For loop example
For m=[ 4 -1 0]
X=2*m
Y=m+5
End
User defined function
MATLAB program created by the user, saved as a function file, and can be used like a built in function when in the current folder
UDF syntax
function [output1,output2,...] = function_name (Input1,input2,...)
complex loop
Uses combination of for loops, while loops
MATLAB Order of Operations
Parentheses
Exponentiation
Negation
Mult/divi
Add/sub
log(x)
Natural log
exist('')
Check if variable name is a built in function
log10(x)
log base 10
cos(x)
Cosine
cosd(x)
cosine of x in degrees
Variable naming rules
1. Variables should have a descriptive name that describes their purpose without being too long
2. Variable names cannot start with numbers or have spaces or special characters except for an underscore
3. Variables are case sensitive
Array
A collection of data whose elements are arranged in rows and/or cols, can be stored and manipulated
Scalar
One-element array
Vector
One-dimensional array
Matrix
Two-dimensional array(elements are arranged in rows and cols)
Row vectors
Created with brackets and commas but commas aren't necessary
Column vectors
Created with brackets and semicolons or .' To transpose
Transpose
.' Or transpose[ ]
Regularly spaced vectors
Start:step:end
0:10:50
0 10 20 30 40 50
Linearly spaced vector
Linspace(start,end,number of elements)
Linspace(0,55,6)
0 11 22 33 44 55
Never require a period character
-addition and subtraction
-multiplication of scalar and array
-division of array by scalar
Always require a period character
-multiplication, division, and exponentiation of arrays
-division of scalar by array
-exponentiation involving a scalar
Array indexing
Array elements are referenced by their row and column location
Array indexing syntax
Array(rows,cols)
: in array indexing
Includes all elements of that dimension
Linear indexing
Array elements are referenced by a single subscript
Down each column
How linear indexing works
Concatenating array
Join arrays together
Side by side concatenation
User_data = [user1 user2 user3]
Stacked concatenation
User_data = [user1; user2; user3]
vertcat
Built in function that concatenates arrays vertically
horzcat
Butler in function that concatenates horizontally
Flowchart rectangle
process
Flowchart diamond
decision
flowchart parallelogram
input and output
Flowchart 2 rectangles
Predefined process
Plotting in matlab
Plot(x,y,linespec)
Plot professional format
Grid on
X label
Y label
Title
Legend
sgtitle('')
Subplot title
axis ([xmin xmax ymin ymax]);
Set axis limits
fprintf function
Displays output or text
\n
new line
%s
String format character
%f
Decimal point
find
Discovers linear index location of all NONzero elements
AND (&)
Which is evaluated first and(&) or or(|)
Between in matlab
x >= A & x<= B
==
Equal to