basic MATLAB operations Flashcards
(26 cards)
How would you wirte a first step last operation?
variable=[first:step:last]
Form a row vector
a=[2 3 5]
Form a column vector
b=[3;1;8]
Form a 2x2 matrix
c=[1 2;7 8]
Size of a vector a
size(a)
Size of row of vector a
size(a,1)
Size of column of vector a
siza(a,2)
absolute function
abs
natural logorithim
log
What does A(4,:) show
all elemnts in 4th row of matrix A
What does A([1 3],[2 4]) show
elements in rows 1&3, columns 2&4
How to plot a graph (2 steps)
1) define graph f(x)=
2) fplot(f, [-1:1]):
How would you write a linspace operation?
a=linspace(first,last,N)
create an array of all zeros
z=zeros(m,n)
create an array of all ones
o=ones(m,n)
create an array of random numbers
r=rand(m,n)
How to clear window (keeps memory)
clc
Write an identity matrix (ixi)
a=eye(i)
How to see all variables
whos
Overwriting arrays
Part of a matrix replaced by an identity matrix B
part needing replacing = new part
A(3:5,2:4)=B
What are semicolons used for?
Supresses working out, code is still run but output stored in workplace
for ones,zeros,rands and eye all ixi matrices can be represented similiary, how?
A=” “(i)
Sidenote!!!!!
remember to name variables!!!!!!!!!!!!!!!
Sidenote 2!!!!
arrays need square brackets!!!!!