필터 지우기
필터 지우기

Reducing values preceding the 1st minima to zero

조회 수: 1 (최근 30일)
Tom
Tom 2014년 7월 22일
댓글: Azzi Abdelmalek 2014년 7월 22일
I need to reduce the value of all the values before the 1st minima, to zero, e.g. if I had: -
x = 0:30;
y = [10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 5 4 3 2 3 4 3 2 1 0.5 0.3 0.2 0.1 0]';
figure(1)
plot(x,y)
ylim([0 10])
then I need a bit of code that changes it to: -
z = [0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 5 4 3 2 3 4 3 2 1 0.5 0.3 0.2 0.1 0]';
figure(2)
plot(x,z)
ylim([0 10])
instead.
Can anyone suggest something?
Many thanks.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 22일
편집: Azzi Abdelmalek 2014년 7월 22일
y = [10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 5 4 3 2 3 4 3 2 1 0.5 0.3 0.2 0.1 0]';
[~,jj]=findpeaks(-y,'npeaks',1)
z=y
z(1:jj)=0
  댓글 수: 2
Tom
Tom 2014년 7월 22일
Many thanks!
Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 22일
You can also use gradient
g=gradient(y);
idx=find(g==0 & gradient(g)>0,1)
z=[zeros(idx,1) ;y(idx+1:end)]

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 7월 22일
편집: Andrei Bobrov 2014년 7월 22일
ii = find(diff(diff(y)<0)==-1,1)+1;
y1=y;
y1(1:ii)=y(ii);
or
ii = strfind([0,diff(y(:)')<0],[1 0]);
y1=y;
y1(1:ii(1)) = y(ii(1));

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by