SUNY Geneseo Department of Mathematics
Wednesday, February 10
Math 230 02
Spring 2016
Prof. Doug Baldwin
>> % Find elements less than 0.5 in vector of random numbers
>> v = rand( 1, 6 )
v =
0.2785 0.5469 0.9575 0.9649 0.1576 0.9706
>> smallPositions = v < 0.5
smallPositions =
1 0 0 0 1 0
>> v( smallPositions )
ans =
0.2785 0.1576
>> % How many of those small numbers were there?
>> length( v( smallPositions ) )
ans =
2
>> sum( smallPositions )
ans =
2
>> % Pick out the elements that aren’t less than 0.5
>> newV = v( [false true true true false true ] )
newV =
0.5469 0.9575 0.9649 0.9706
>> newV = v( v >= 0.5 )
newV =
0.5469 0.9575 0.9649 0.9706
>> newV = v( ~ smallPositions )
newV =
0.5469 0.9575 0.9649 0.9706
>> % Literally remove the elements less than 0.5 from the vector
>> v
v =
0.2785 0.5469 0.9575 0.9649 0.1576 0.9706
>> v(smallPositions) = []
v =
0.5469 0.9575 0.9649 0.9706
>> % Pick out elements between -0.1 and +0.1 in another random vector
>> v2 = rand( 1, 6 ) - 0.5
v2 =
0.4572 -0.0146 0.3003 -0.3581 -0.0782 0.4157
>> v2( -0.1 <= v2 & v2 <= 0.1 )
ans =
-0.0146 -0.0782
findPeaks
function?help findpeaks
produces something, or typing findp
and then pressing the tab key in the command window offers findpeaks
as a completion, then your Matlab has it>> wave = sin( 6 * linspace(0,2*pi,100) );
>> findpeaks( wave )
>> peaks = findpeaks( wave )
peaks =
0.9989 0.9898 0.9989 0.9898 0.9989 0.9898