How to find how many values in one column in csv file?

2 ビュー (過去 30 日間)
Cagla
Cagla 2023 年 4 月 27 日
回答済み: chicken vector 2023 年 4 月 27 日
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?

回答 (1 件)

chicken vector
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))'
ans = 1×2
1 1
And for zeros:
j = 100;
data(endIdx(j-1)+1:startIdx(j)-1)'
ans = 1×5
0 0 0 0 0
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))'
ans = 1×5
0 0 0 0 0

カテゴリ

Help Center および File ExchangeString についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by