How to find how many values in one column in csv file?
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
chicken vector
on 27 Apr 2023
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 Comments
See Also
Categories
Find more on String in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!