Creating a run log/count with a for loop within a table.
3 ビュー (過去 30 日間)
古いコメントを表示
I have a table that has a time column and a binary stability column (1 for stable data, 0 for non). I want to create a run count / run log for the stable data as shown below. The idea is to group stable data into "runs" then breakdown the table and export these runs into separate tables or to identify what range in which a run occurs. The table is rather long ~30000 lines, so I figured a for loop would be best but I am having difficulty identifying the conditional criteria. I appreciate any assistance.
1 件のコメント
回答 (1 件)
Stijn Haenen
2020 年 3 月 10 日
編集済み: dpb
2020 年 3 月 10 日
I think this is what you are looking for:
switch_list=zeros(length(data),1);
switch_list(2:end)=data(2:end,2)-data(1:end-1,2);
up_list=find(switch_list==1);
down_list=find(switch_list==-1)-1;
for i=1:length(up_list)
data(up_list(i):down_list(i),3)=i;
end
I made my own data:
data = [
1 0
2 0
3 0
4 1
5 1
6 0
7 0
8 1
9 0
10 0
11 1
12 1
13 1
14 0
15 0
16 0
17 0
18 1
19 1
20 1
21 0
22 0
23 0
24 1
25 1
26 0
27 1
28 0];
7 件のコメント
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!