# JavaScript state

Definition

A custom variable that processes raw data (for example, the subject coordinates, or the distance moved) and produces a state (on/off) value for each sample of the track, based on an algorithm.

Use cases

▪Velocity bins. Get the per-sample values of velocity and create velocity bins, for example from 0 to 100 mm/s, from 100 to 200 mm/s etc.

▪Aggregation detector. Calculate the number of subjects present in a zone and set the output of the variable to 1 if the number of subjects exceeds a certain threshold. Use this variable for example to calculate the time that more than 50% of the subjects cluster in one zone.

▪tip Browse to my.noldus.com, log in or register and choose Downloads > EthoVision XT > Drivers and tools. There you can download examples of JavaScript state variables. Simply copy the code to the JavaScript State window and follow the instructions (see below).

Calculation

The main difference with the JavaScript continuous variable is that the value calculated per sample and specified in SetOutput() is either 0 or 1. The variable has a duration based on the total number of 1s in the track or selected track segment.

See JavaScript continuous > Calculation

How to specify a JavaScript state variable

1.In the Analysis profile, under Custom Variables, click the button next to JavaScript state.

2.Enter the code in the JavaScript State window.

3.Next to Number of outputs, select the number of possible states of the variable. For example, in the Velocity example described above, select 4.

4.Follow the rest of the procedure in JavaScript continuous > To specify a JavaScript continuous variable.

Notes

▪In the Trial Statistics tab, select Cumulative Duration to calculate the total time that the state variable is “on”.

See also

▪JavaScript continuous

▪JavaScript event

▪Commands and functions for JavaScript variables