フィルターのクリア

Removing rows from a column depending on another column

1 回表示 (過去 30 日間)
Christopher
Christopher 2013 年 9 月 8 日
Hello,
I need a little bit of help with this problem. I will explain it the best I can then give a basic example below. Basically I have two column vectors. I am trying to split one of them up depending on the other. Basically I have:
Cp=[0;0.2;0.4;0.6;0.8;1;1.2;1.4];
Cf=[0;1;2;3;4;5;6;7;8];
I am trying to split up Cf depending on when Cp hits 1. So essentially, when Cp<=1 I am trying to obtain a column for Cf with only those values. So the resultant Cf would be:
Cf_new=[0;1;2;3;4;5]
So the only values obtained for Cf are when the corresponding row of Cp is less than or equal to 1. I hope this makes sense. Thank you

採用された回答

Image Analyst
Image Analyst 2013 年 9 月 8 日
Regarding your new question about extracting values of Cf only up to and including the index of the peak in Cp:
Cp=[0.2 0.4 0.8 0.99 0.8 0.4 0.2]
Cf=[0;1;2;3;4;5;6;7;8]
peakIndex = find(diff(Cp) < 0, 1, 'first')
Cf_new = Cf(1 : peakIndex)
In the command window:
Cp = 0.2 0.4 0.8 0.99 0.8 0.4 0.2
Cf =
0
1
2
3
4
5
6
7
8
peakIndex =
4
Cf_new =
0
1
2
3

その他の回答 (2 件)

the cyclist
the cyclist 2013 年 9 月 8 日
Cf_new = Cf(Cp<=1);
  4 件のコメント
Christopher
Christopher 2013 年 9 月 8 日
Yes, but the problem is all the values are less than 0.99, so it returns the entire original Cf column. Some how I need to obtain the number of rows from the beginning of Cf until it hits the peak.
Image Analyst
Image Analyst 2013 年 9 月 8 日
That's a different question than you first asked. How are you defining "peak"? There is a findpeaks() function in the Signal Processing Toolbox. Or else you could just call diff(Cp) and look for the first negative value - it just depends on how you want to define a "Peak."

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


Andrei Bobrov
Andrei Bobrov 2013 年 9 月 8 日
編集済み: Andrei Bobrov 2013 年 9 月 8 日
out = Cf(1:find(Cp>=.99,1,'first'));

カテゴリ

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