필터 지우기
필터 지우기

trying to find peaks on a time series

조회 수: 8 (최근 30일)
DuckDuck
DuckDuck 2012년 6월 11일
i'm trying to find peaks on some time series data but when i write
[pks,locs]=findpeaks(x)
i get the position of peak on locs. but i want to get the locs the same length i have x files or better if i have locs represented as 0 and 1 i can get the x values without a hassle. is there an elegant and simple way of dooing it, like the find function??
i also am trying this but obviously it takes time because of the loops, is there any simple way of dooing this in matlab.
newx=zeros(length(xn),1);
for p=1:length(xn);
for m=1:length(locs);
if locs(m)==p
newx(p)=1;
else
end;
end;
end;
end;
  댓글 수: 2
Ryan
Ryan 2012년 6월 11일
I am confused, if you have the locations of the peaks already, what is the issue? What type of location information is stored in locs?
DuckDuck
DuckDuck 2012년 6월 11일
look at my code, i want to know if there is a better way of writing that code, because loops take a long time in matlab

댓글을 달려면 로그인하십시오.

채택된 답변

Wayne King
Wayne King 2012년 6월 11일
I'm assuming that xn in your loop above is the signal. You don't show us where xn comes from and it's not used in your call to findpeaks(). In your call to findpeaks, you use x. So If that is the case, then you don't need a loop.
newx = zeros(size(x));
newx(locs) = 1;
Does the same thing as your loop.
  댓글 수: 1
DuckDuck
DuckDuck 2012년 6월 11일
yeah you are right, basically xn is s x.
no it does not, i tried and it did not.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Wayne King
Wayne King 2012년 6월 12일
Then please compare:
x = [2 12 4 6 9 4 3 1 19 7];
[pks,locs] = findpeaks(x);
% here is your code
newx=zeros(length(x),1);
for p=1:length(x);
for m=1:length(locs);
if locs(m)==p
newx(p)=1;
else
end
end
end
Now what I answered:
newx2 = zeros(length(x),1);
newx2(locs) = 1;
Now
isequal(newx,newx2)
That returns a 1 for me.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by