MATLAB: Returning peak values from a column

column vectormalabpeak value

Hello,
I am trying to do the following. I have two column vectors:
Cp=[0;0.4;0.8;0.99;0.8;0.4;0];
Cf=[1;2;3;4;5;6;7];
I am trying to obtain a Cf column vector for the corresponding Cp column vector peak and below. So Cp peaks at 0.99 and I am trying to obtain the values for Cf from the beginning of Cp until the peak of Cp. All of the values of Cp are less than the peak value.
So
Cf_new=[1;2;3;4]
I am also trying to obtain the last half of Cf for Cp after the peak until the end. So the last half would be:
Cf_new2=[5;6;7]
Thank you

Best Answer

[~,idx]=max(Cp);
Cf_new=Cf(1:idx);
Cf_new2=Cf(idx+1:end);