MATLAB Answers

Finding length between two array elements.

1 view (last 30 days)
Hrishikesh Dalal
Hrishikesh Dalal on 3 Dec 2019
Answered: the cyclist on 3 Dec 2019
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 Comments

Show 2 older comments
David Goodmanson
David Goodmanson on 3 Dec 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 on 3 Dec 2019
Thanks for the reply David i will work it out
David Goodmanson
David Goodmanson on 3 Dec 2019
Hrishikesh,
I posted the wrong expression for z in the comment but it is fixed now.

Sign in to comment.

Answers (1)

the cyclist
the cyclist on 3 Dec 2019
The RunLength utility from the File Exchange might be handy. Run it in a loop over each column.

  0 Comments

Sign in to comment.

Sign in to answer this question.