Last active
October 30, 2015 01:50
-
-
Save dzonesasaki/1e12f6e744127689eb40 to your computer and use it in GitHub Desktop.
find peak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [resultPeak,resultIndex,strmzeroWoPeak] = findpeaksDzone(InDat) | |
Ndat = length(InDat); | |
[sizeC,sizeR] = size(InDat); | |
if Ndat~=(sizeC*sizeR) | |
errMess = sprintf('stream not single vector [%d,%d] ;_;',[sizeC,sizeR]); | |
error(errMess) | |
end | |
Dat = reshape(InDat,Ndat,1); | |
DiffFoward = [0; Dat(2:(end)) - Dat(1:(end-1))]; | |
%DiffBackward = [flipud( InDat((end-1):-1:1) - InDat((end):-1:2) );0]; | |
DiffBackward = [ Dat(1:(end-1)) - Dat(2:(end));0]; | |
peaksFlag = (DiffFoward>0).*(DiffBackward>0); | |
[resultIndex]=find(peaksFlag); | |
resultPeak=Dat(resultIndex); | |
strmZeroOrPeak =reshape(peaksFlag.*Dat,sizeC,sizeR); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment