How to find how many values in one column in csv file?
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a csv file that contains 0s and 1s in one column, 2160 rows like in the image below.
I want to know the range which contains 1s like: 1-130, 250-400, etc.
and also i want to do this for 0s. I tried a few code but i couldnt do it. Could you please help me?
0 件のコメント
回答 (1 件)
chicken vector
2023 年 4 月 27 日
Once you upload the data from you .csv you can find start and end indeces by doing:
data = randi(2,1e3,1) - 1;
startIdx = strfind([0 data'],[0 1]);
endIdx = strfind([data' 0],[1 0]);
You can access the jth block of 1s by doing:
j = 100;
data(startIdx(100):endIdx(100))'
And for zeros:
j = 100;
data(endIdx(j-1)+1:startIdx(j)-1)'
Alternatively you can find indeces corresponding to zeros as:
startIdx = strfind([1 data'],[1 0]);
endIdx = strfind([data' 1],[0 1]);
j = 100;
data(startIdx(j):endIdx(j))'
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で String についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!