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!