## Reducing values preceding the 1st minima to zero

### Tom (view profile)

on 22 Jul 2014
Latest activity Commented on by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 22 Jul 2014
Accepted Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

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])
Can anyone suggest something?
Many thanks.

### Azzi Abdelmalek (view profile)

Answer by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 22 Jul 2014
Edited by Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 22 Jul 2014

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

Tom

on 22 Jul 2014
Many thanks!
Azzi Abdelmalek

### Azzi Abdelmalek (view profile)

on 22 Jul 2014
You can also use gradient
z=[zeros(idx,1) ;y(idx+1:end)]

### Andrei Bobrov (view profile)

Answer by Andrei Bobrov

### Andrei Bobrov (view profile)

on 22 Jul 2014
Edited by Andrei Bobrov

### Andrei Bobrov (view profile)

on 22 Jul 2014

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));