Returning peak values from a column

1 回表示 (過去 30 日間)
Christopher
Christopher 2013 年 9 月 8 日
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

採用された回答

Matt J
Matt J 2013 年 9 月 8 日
[~,idx]=max(Cp);
Cf_new=Cf(1:idx);
Cf_new2=Cf(idx+1:end);

その他の回答 (2 件)

Image Analyst
Image Analyst 2013 年 9 月 8 日
編集済み: Image Analyst 2013 年 9 月 8 日
peakIndex = find(diff(Cp) < 0, 1, 'first')
Cf_new = Cf(1 : peakIndex)
Cf_new2 = Cf(peakIndex+1:end)
In the command window:
peakIndex =
4
Cf_new =
1
2
3
4
Cf_new2 =
5
6
7
Or you might mean "max value" instead of peak. In that case you need to use max() instead of diff(), and you need to know what you want to do if you have a run of several max values in a row.
  1 件のコメント
Christopher
Christopher 2013 年 9 月 8 日
Thanks Image Analyst

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2013 年 9 月 8 日
編集済み: Andrei Bobrov 2013 年 9 月 8 日
t = [true;diff(Cp(:))>=0]
Cf_new = Cf(t);
Cf_new2 = Cf(~t);

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by