Count episodes and overlapping hot windows

A thermal test records the following temperatures in degrees Celsius at times 0 through 9 s, one reading per second. The MATLAB code analyzes only these recorded samples; no interpolation between readings is assumed.


MATLAB
T = [74 76 71 75 77 79 78 70 72 74];
hot = T > 72;
previous = [false hot(1:end-1)];
beforePrevious = [false false hot(1:end-2)];
starts = hot & ~previous;
triples = hot & previous & beforePrevious;
nStarts = sum(starts);
nTriples = sum(triples);


Ten temperature readings are plotted against time with a horizontal threshold at 72 degrees Celsius.


An episode starts when a hot reading follows a non-hot reading. The inserted false values mean the first recorded reading starts an episode if it is hot. A three-sample window qualifies when all three consecutive recorded readings are hot, and overlapping windows count separately.


Determine nStarts, the number of episode starts, and nTriples, the number of qualifying three-sample windows. Enter both counts as exact integers.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Vectorized Code and Logical Operations Questions: