How to calculate Cycles

14 ビュー (過去 30 日間)
Mekala balaji
Mekala balaji 2018 年 2 月 22 日
コメント済み: Mekala balaji 2018 年 2 月 23 日
Hi,
I have data, want to calculate cycles after each reset of lifetime(each cycle life hours are different),
lifeHours
0.2
3
12
18
22
0.8
1.5
2.9
5
8
11
17
1
4
5
8
13
17
23
28
Desired Output: Cycles start from 1
Cycles
1
1
1
1
1
2
2
2
2
2
2
2
3
3
3
3
3
3
3
3
Many thanks in advance,
  1 件のコメント
Mekala balaji
Mekala balaji 2018 年 2 月 23 日
Sir Thanks, it works

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

採用された回答

Star Strider
Star Strider 2018 年 2 月 22 日
If you have R2015 or later, you can use the repelem (link) function.
Defining ‘v’ as your vector:
[~,locs] = findpeaks(-v); % Find Minima
tlocs = [1; locs; numel(v)+1]; % Define Cycle Limits
dlocs = diff(tlocs); % Cycle Lengths
Output = repelem([1 2 3], dlocs)'; % Vector Of Cycle Designations (R2015a & Later)
Cycles = [v Output]
Cycles =
0.2 1
3 1
12 1
18 1
22 1
0.8 2
1.5 2
2.9 2
5 2
8 2
11 2
17 2
1 3
4 3
5 3
8 3
13 3
17 3
23 3
28 3

その他の回答 (1 件)

Pawel Jastrzebski
Pawel Jastrzebski 2018 年 2 月 22 日
編集済み: Pawel Jastrzebski 2018 年 2 月 22 日
Consider the following code:
data = [0.2 3 12 18 22 0.8 1.5 2.9 8 11 17 1 4 5 8 13 17 23 28]'
% preallocation
cycle(length(data),1) = 0
% manually mark a beginning of the first cycle
cycle(1) = 1;
for i=2:length(data)
if data(i)>data(i-1)
cycle(i) = cycle(i-1);
else
cycle(i) = cycle(i-1)+1;
end
end
cycle
The output:
>> cycle
cycle =
1
1
1
1
1
2
2
2
2
2
2
3
3
3
3
3
3
3
3

カテゴリ

Help Center および File ExchangeMonte Carlo Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by