Collects data from a VarsList and provides ways to print or access that data. The data is stored in a HistoryList with each entry being an array of numbers (a 'data sample') representing the value of the variables at a point in time.

The data is stored whenever memorize is called. As a Memorizable the VarsHistory can be connected to a MemoList such as SimRunner. In most myPhysicsLab apps the following commands entered in Terminal will set this up:

var hist = new VarsHistory(sim.getVarsList());

To memorize the starting initial conditions, call the memorize function once before starting the simulation.


Run the simulation as long as desired. After the simulation run is completed, print the data:


The resulting text can then be copied from the Terminal text box, saved as a text document and imported into a spreadsheet program or graphed with a Python script.

The default separator between numbers is the tab character. To instead use comma separated values:

hist.setSeparator(', ')

To change which variables are sampled or the order of the variables within each sample use setVariables. For example:


Note that setVariables erases all stored data, so you would need to call memorize afterwards to store initial conditions.

The default format for printing numbers gives 5 decimal places, but if the number is too small then switches to exponential format. Use setNumberFormat to change the formatting function. For example:

hist.setNumberFormat((n) => n.toFixed(2));

That example uses an arrow function but you can provide any function that takes one numeric argument and returns a string.

To process the data using Javascript use the toArray method

var a = hist.toArray()




numberFormat: ((n) => string) = Util.NF5E

number formatting function

Type declaration

    • (n): string
    • number formatting function


      • n: number

      Returns string

separator: string = '\t'

separator between numbers

varIndex_: number[]

Set of index numbers into VarsList, specifies which variables to memorize.


  • Returns the array of variable index numbers specifying which variables to remember.

    Returns number[]

    array of variable index numbers specifying which variables to remember

  • Returns string form of the data points. One line for each sample, using the number formatting function and text separator specified by the properties numberFormat and separator.


    • Optional opt_localized: boolean

      true means print the localized versions of the variable names; false means print the language independent variable names; default is true

    Returns string

  • Parameters

    • numberFormatFn: ((n) => string)

      the number formatting function; takes one numeric argument, returns a string.

        • (n): string
        • Parameters

          • n: number

          Returns string

    Returns void

  • Set the separator string to print between numbers


    • separator: string

      the separator string to print between numbers. Default is a comma and space.

    Returns void

  • Sets the array of variable index numbers specifying which variables to memorize. This calls reset which erases all stored data.


    • varIndex: number[]

      array of variable index numbers specifying which variables to memorize

    Returns void

  • Returns arrays of the data points, one array for each sample.

    Returns number[][]

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:


    Returns string

    a minimal string representation of this object.

Generated using TypeDoc