Showing posts with label matlab. Show all posts
Showing posts with label matlab. Show all posts
Monday, December 7, 2009
MATLAB findpeaks function
The findpeaks function in the MATLAB (verion 7.6.0.324) Signal Processing Toolbox finds local maxima or peaks in a vector.
>> v = [0 3 0 0 3 2];
>> [pks, locs] = findpeaks(v)
pks =
3 3
locs =
2 5
locs contains the locations or indices of the peaks in v (MATLAB indexing starts at 1).For each column of a 256 x 5188 matrix we were calculating a simple moving average (
smooth function) and then finding the peaks and it was taking a long time, approximately 19.6 seconds. We whipped up our own findpeaks function based on the following two lines:This calculates the pairwise differences between elements, i.e. the slopes and then looks for an up slope immediately followed by a down slope. Pretty simple and now the 5188 matrix columns are processed in approximately 1.3 seconds.
>> s=v(2:end)-v(1:end-1);
>> loc=find((s(1:end-1)>0) & (s(2:end)<0)) + 1
loc =
2 5
Labels:
matlab
Thursday, September 24, 2009
R Resources
Been learning to use R for a stats subject. These links were useful.
Other things I have stumbled across along the way.
- R - Resources
- Rattle GUI for data mining in R
- SNA in R Talk, Updated with [Better] Video
- Revolutions blog
Update 1/11/2009
For completeness I should also have included An Introduction to R that comes bundled with R, as well as the official R Wiki. Also discovered RSeek.org as well as this MATLAB / R Reference.
Subscribe to:
Comments (Atom)