?? locmax.m
字號:
function z=locmax(x)
%
% z=locmax(x):
%
% Function to identify local maxima points of a physical signal
% and their coordinates.
%
% Input-
% x - input vector of values
% Output-
% z - 2-D matrix z(m,2) where
% 1st column specifies the coordinates
% of max values in the order found
% 2nd column specifies the corresponding max values
%
% Jelena Marshak (NASA GSFC) March 9, 2004 Edited
%----- Find the input data length
nn=length(x);
%----- Initialize values
w=zeros(nn,2);
zmax=x(1);
zmin=x(1);
d_tp=0; %temple index of possible max, min
d_i=1; %corresponding t
if(x(1)==x(2) & x(2)>x(3)) %initialize d_tp
d_tp=1;
end
count=0;
%----- Find the extrema
for i=3:nn-2
if (x(i-1)<x(i) & x(i)>x(i+1))
count=count+1;
w(count,1)=i;
w(count,2)=x(i);
elseif(x(i-1)==x(i) & x(i)>x(i+1))
if(d_tp>0)
count=count+1;
w(count,1)=ceil((d_i+(i-d_i)/2));
w(count,2)=x(ceil(d_i+(i-d_i)/2));
d_tp=0;
end
elseif(x(i)>x(i-1) & x(i)==x(i+1))
d_tp=1;
d_i=i;
end
end
if(x(nn-1)==x(nn)) %end-condition
if(d_tp>0)
count=count+1;
w(count,1)=ceil((d_i+(nn-d_i)/2));
w(count,2)=x(ceil(d_i+(nn-d_i)/2));
end
end
z=zeros(count,2);
for i=1:count
z(i,1)=w(i,1);
z(i,2)=w(i,2);
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -