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

5 visualizaciones (últimos 30 días)
Cagla
Cagla el 27 de Abr. de 2023
Respondida: chicken vector el 27 de Abr. de 2023
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?

Respuestas (1)

chicken vector
chicken vector el 27 de Abr. de 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))'
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

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by