필터 지우기
필터 지우기

Help to build the logic to plot peak vs time

조회 수: 1 (최근 30일)
Jeevan Patil
Jeevan Patil 2012년 1월 19일
t = 0:0.1:10;
y = 15*sin(pi*t);
[a,b]=peakdetection(y,0.5);
if y(i) == a;
y(i) = y(i);
else
y(i)= 0;
end
In this i want to detect peak and valley from any type of signal. After detecting i want to plot only peak against time. All other value of y (except peak) should be zero as per my requirement.
I will appreciate if anybody help me to build this logic. I tried to use if loop but it is given error
??? Subscript indices must either be real positive integers or logicals.
Error in ==> Untitled at 7
if y(i) == a;
Regards
Jeevan Patil

채택된 답변

David
David 2012년 1월 19일
i is an imaginary number by default causing your error.
Wrap your code in a for loop
for ii=1:length(y)
if y(ii)~=a
y(ii)=0;
end
end
However you might find difficulties comparing floating point numbers. You may need to have some sort of compare function:
realCmp = @(x,y) abs(x-y)<1000*sqrt(eps)
And use
if ~realCmp(y(ii),a)
However even better that that you should use
y(~realCmp(y,a))=0;
and avoid the for loop altogether

추가 답변 (1개)

Jeevan Patil
Jeevan Patil 2012년 1월 21일
Thanks David,
logic given by you is working. problem was not with i, it was with logic only.
thanks again

카테고리

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