Documente Academic
Documente Profesional
Documente Cultură
M.
Transpose operation
a vector x
x = 1
2 5
= [1 2 5 1]
transpose y
= x
y = 11
Transpose operation
z = [1; 2; 3; 4]
z=
1 2 33 4
z'
ans =
1 2
Logical Operators
You can use Logical Indexing to find data
that conforms to some limitations
Logical Operators:
Greater Than: >
Less Than: <
Greater Than or Equal To: >=
Less Than or Equal To: <=
Is Equal: ==
Not Equal To: ~=
Built-in Functions
numbers on
(0,1)x =
zeros(1,
3) x =
0
x = ones(1,3)
x =x = 1 1 1
rand(M,N) MxN matrix of uniformly
distributed random
x =
rand(1,3)
x =
For example,
>> zeros(2,2) ans =
0 0 0 0
>> ones(4,3) ans =ans =
111111 111111
1
5
16
StandardArrays
eye(2)
ans =
1
00
eye(2,3)
ans =
1
00
x = start:increment:end
linspace(start,end,number)
length(x)
y = x
Plots
x = 1:2:50; y = x.^2; plot(x,y)
Plots
plot(x,y,'*-') xlabel('Values of x') ylabel('y')
Example
Generate and plot a cosine function
x = [0:0.01:2*pi];
y = cos(x);
plot(x,y)plot(x,y)
2
Example
Adding titles to graphs and axis
title(this is the title)
xlabel(x)
ylabel(y)ylabel(y)
2
-x/3Plot
>>x=linspace(0,4*pi,100);
-x/3Plot
0.
>>plot(y
2)0.6
0.2
0.5
0.4
0.3
0.1
0
-0.1
-0.2
0 10 20 30 40 50 60 70 80 90 100 -0.
CREATING A PLOT OF A
FUNCTION111112
A PLOT OF A FUNCTION
4
2for)
6cos(
5.3x
xy11
111
5.0x
Functions
MATLAB
many operations
built in functions
a variety
of has
statistical
Special functions
There are a number of special functions that
provide useful constants
pi = 3.14159265.
ior j = square root of -1
Inf = infinity Inf = infinity
NaN = not a numbe
Functions
Passing a vector to a function like sum, mean,
will calculate the property within the vector
>>
sum([1,2,3,4,5])
= 15
>>
mean([1,2,3,4,5])
=3
2
9