Finding length between two array elements.

i have an array consisting of 1's and 0's. 1-> generators on and 0's-> generators off. I need to find lengths for which the generators remain off. the array is 44*8760 values. Attaching the file as worspace.

5 commentaires

Hank
Hank le 3 Déc 2019
Could you describe what you mean by the lengths?
Hrishikesh Dalal
Hrishikesh Dalal le 3 Déc 2019
So, the number of zeros represent the hours for which the generator is off. See attachment. So i need to find the lenghts of all the zeros (all the hours for which generator is off) . In the screnshot, the first column for which zeros are ocurring has a count of 7. and then 1's followed by again zeros for which the count is 6. It simply means, my generator is off for 7 hours then its switching on and again off for 6 hours. this is what i need for all generators.
David Goodmanson
David Goodmanson le 3 Déc 2019
Modifié(e) : David Goodmanson le 3 Déc 2019
HI Hrishikesh,
for a single row of values x,
z = diff(find(diff([inf x inf])))
za = z(1:2:end)
zb = z(2:2:end)
gives a set of 'on' lenghts and a set of 'off' lengths. Which is which,
depends on whether x starts off with a 0 or a 1. With the aid of a small example you can work that out.
Hrishikesh Dalal
Hrishikesh Dalal le 3 Déc 2019
Thanks for the reply David i will work it out
David Goodmanson
David Goodmanson le 3 Déc 2019
Hrishikesh,
I posted the wrong expression for z in the comment but it is fixed now.

Connectez-vous pour commenter.

Réponses (1)

the cyclist
the cyclist le 3 Déc 2019

0 votes

The RunLength utility from the File Exchange might be handy. Run it in a loop over each column.

Catégories

En savoir plus sur Operators and Elementary Operations dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by