Functions

A growing list of functions that you can use in formulas and scripting...

`abs` (`x`) – absolute value
`abs#` (`vector#`) – absolute value of each element of `vector#`
`abs##` (`matrix##`) – absolute value of each cell of `matrix##`
`appendFile` (`filePath\$`, `...`) – write texts, numbers, vectors and so on at the end of an existing file (create such a file if it does not exist yet)
`appendFileLine` (`filePath\$`, `...`) – write texts, numbers, vectors and so on, followed by a newline, at the end of an existing file (create such a file if it does not exist yet)
`appendInfo` (`...`) – write texts, numbers, vectors and so on, to the Info window
`appendInfoLine` (`...`) – write texts, numbers, vectors and so on, followed by a newline, to the Info window
`arccos` (`x`) – inverse cosine
`arccos#` (`vector#`) – inverse cosine of each element of `vector#`
`arccos##` (`matrix##`) – inverse cosine of each cell of `matrix##`
`arccosh` (`x`) – inverse hyperbolic cosine
`arccosh#` (`vector#`) – inverse hyperbolic cosine of each element of `vector#`
`arccosh##` (`matrix##`) – inverse hyperbolic cosine of each cell of `matrix##`
`arcsin` (`x`) – inverse sine
`arcsin#` (`vector#`) – inverse sine of each element of `vector#`
`arcsin##` (`matrix##`) – inverse sine of each cell of `matrix##`
`arcsinh` (`x`) – inverse hyperbolic sine
`arcsinh#` (`vector#`) – inverse hyperbolic sine of each element of `vector#`
`arcsinh##` (`matrix##`) – inverse hyperbolic sine of each cell of `matrix##`
`arctan` (`x`) – inverse tangent
`arctan#` (`vector#`) – inverse tangent of each element of `vector#`
`arctan##` (`matrix##`) – inverse tangent of each cell of `matrix##`
`arctan2` (`y`, `x`) – argument angle
`arctanh` (`x`) – inverse hyperbolic tangent
`arctanh#` (`vector#`) – inverse hyperbolic tangent of each element of `vector#`
`arctanh##` (`matrix##`) – inverse hyperbolic tangent of each cell of `matrix##`
`assert` `condition` – condition checking
`asynchronous` – let the script continue while the sound is playing
`backslashTrigraphsToUnicode\$` (`string\$`) – convert e.g. \ct to ɔ
`barkToHertz` (`x`) – from Bark-rate to acoustic frequency
`besselI` (`n`, `x`) – modified Bessel function of the first kind, In
`besselK` (`n`, `x`) – modified Bessel function of the second kind, Kn
`beta` (`x`, `y`) – β function
`between_by#` (`low`, `high`, `step`) – symmetrically dispersed numbers between `low` and `high`, in steps of `step`
`between_count#` (`low`, `high`, `n`) – `n` symmetrically dispersed numbers between `low` and `high` (bin centres)
`binomialP` (`p`, `k`, `n`) – probability of Bernoulli event occurring at most `k` in `n` times
`binomialQ` (`p`, `k`, `n`) – probability of Bernoulli event occurring at least `k` in `n` times
`ceiling` (x) – round up to integer
`ceiling#` (`vector#`) – round up each element of `vector#`
`ceiling##` (`matrix##`) – round up each cell of `matrix##`
`center` (`v#`) – center (or centre) of gravity
`chiSquareP` (`chiSquare`, `df`) – area under the χ2 curve up to `chiSquare`
`chiSquareQ` (`chiSquare`, `df`) – area under the χ2 curve after `chiSquare`
`chooseFolder\$` (`title\$`) – pops up a folder selection window
`chooseReadFile\$` (`title\$`) – pops up a file selection window for opening (or appending to) an existing file
`chooseWriteFile\$` (`title\$`, `defaultFilename\$`) – pops up a file selection window for saving to a new file
`clearinfo` – clear the Info window
`columnSums#` (`matrix##`)
`correlation` (`u#`, `v#`) – correlation (between −1 and +1) of two vectors
`cos` (`x`) – cosine
`cos#` (`vector#`) – cosine of each element of `vector#`
`cos##` (`matrix##`) – cosine of each cell of `matrix##`
`cosh` (x) – hyperbolic cosine
`cosh#` (`vector#`) – hyperbolic cosine of each element of `vector#`
`cosh##` (`matrix##`) – hyperbolic cosine of each cell of `matrix##`
`createFolder` (`folderPath\$`) – create a new folder, or do nothing if it already exists
`date\$` ( ) – current local date and time in the form "Mon Nov 8 16:32:42 2021"
`date_iso\$` ( ) – current local date and time in the form "2021-11-08T16:32:42+01:00"
`date#` ( ) – current local date and time in the form { 2021, 11, 8, 16, 32, 42 }
`date_utc\$` ( ) – current standard date and time in the form "Mon Nov 8 15:32:42 2021"
`date_utc_iso\$` ( ) – current standard date and time in the form "2021-11-08T15:32:42Z"
`date_utc#` ( ) – current standard date and time in the form { 2021, 11, 8, 15, 32, 42 }
`deleteFile` (`filePath\$`) – delete a file, or do nothing if it does not exist
`demo` – execute a graphics command in the Demo window (instead of in the Picture window)
`demoClicked` ( ) – determine whether the user clicked in the Demo window
`demoClickedIn` (`xmin`, `xmax`, `ymmin`, `ymax`) – determine whether the user clicked in a rectangular region in the Demo window
`demoCommandKeyPressed` ( ) – determine whether the user pressed the Command key when they typed into the Demo window
`demoInput` (`characters\$`) – determine whether the user typed (or clicked) the specified characters into the Demo window
`demoKey\$` ( ) – determine the key that the user typed into the Demo window
`demoKeyPressed` ( ) – determine whether the user typed anything into the Demo window
`demoOptionKeyPressed` ( ) – determine whether the user pressed the Option key when they typed into the Demo window
`demoPeekInput` ( ) – see whether a user event (click or key press) is available in the Demo window
`demoShiftKeyPressed` ( ) – determine whether the user pressed the Shift key when they typed into the Demo window
`demoShow` ( ) – make all deferred drawing commands immediately visible
`demoWaitForInput` ( ) – wait for a user event (click or key press) in the Demo window
`demoWindowTitle` (`newTitle\$`) – change the title of the Demo window
`demoX` ( ) – the horizontal position of a mouse click in the Demo window
`demoY` ( ) – the vertical position of a mouse click in the Demo window
`differenceLimensToPhon` (`x`) – from jnd-scale to perceptual loudness
`editor` (`editor(\$)`) – enter the environment of an editor (by number or by name)
`empty\$#` (`numberOfStrings`) – create an array of empty strings
`endeditor` – leave the environment of an editor
`endproc` – end a procedure definition
`endsWith` (`string\$`, `part\$`) – determine whether `string\$` ends in `part\$`
`environment\$` (`string\$`) – look up a system environment string
`erb` (`f`) – equivalent rectangular bandwidth for frequency `f`
`erbToHertz` (`x`) – from ERB-rate to acoustic frequency
`erf` (`x`) – error function, the integral of the Gaussian
`erfc` (`x`) – complement of the error function, i.e. 1 − erf (`x`); this is a separate function because erf (`x`) can be close to 1
`exitScript` (`...`) – show a message that tells the user why the script will be interrupted
`exp` (`x`) – exponentiation, i.e. e`x`
`exp#` (`vector#`) – exponentiate each element of `vector#`
`exp##` (`matrix##`) – exponentiate each cell of `matrix##`
`extractLine\$` (`string\$`, `part\$`) – everything that comes after the first occurrence of `part\$` in `string\$`
`extractNumber` (`string\$`, `part\$`) – the first number after the first occurrence of `part\$% in %`string
`extractWord\$` (`string\$`, `part\$`) – the first “word” after the first occurrence of `part\$% in %`string
`fileNames\$#` (`folderNameOrPattern\$`) – get the names (not the whole paths) of the files in a folder or that match a pattern with an asterisk
`fileReadable` (`filePath\$`) – 1 if the file exists and can be read, 0 otherwise
`fisherP` (`f`, `df1`, `df2`) – area under the Fisher F curve up to `f`
`fisherQ` (`f`, `df1`, `df2`) – area under the Fisher F curve after `f`
`fixed\$` (`number`, `precision`) – format a number as a string, with `precision` digits after the decimal point
`floor` (`x`) – round down to integer
`floor#` (`vector#`) – round down each element of `vector#`
`floor##` (`matrix##`) – round down each cell of `matrix##`
`folderNames\$#` (`folderNameOrPattern\$`) – get the names (not the whole paths) of the subfolders in a folder or that match a pattern with an asterisk
`from_to#` (`m`, `n`) – the integers from `m` through `n`
`from_to_by#` (`m`, `n`, `step`) – numbers from `m` through `n`, in steps of `step`
`from_to_count#` (`start`, `end`, `n`) – `n` numbers from `start` through `end`
`gaussP` (`z`) – area under the normal curve up to `z`
`gaussQ` (`z`) – area under the normal curve after `z`
`goto` – place in a script to jump from
`hertzToBark` (`x`) – from acoustic frequency to Bark-rate
`hertzToErb` (`x`) – from acoustic frequency to ERB-rate
`hertzToMel` (`x`) – from acoustic frequency to mel
`hertzToSemitones` (`x`) – from acoustic frequency to logarithmic scale re 100 Hz
`imax` (`x`, `...`) – location of the maximum
`imin` (`x`, `...`) – location of the minimum
`index` (`string\$`, `part\$`) – look up a substring, or 0 if not found
`index` (`strings\$#`, `s\$`) – look up whether and where `s\$` first occurs in `strings\$`
`index_regex` (`string\$`, `regex\$`) – determine whether and where `string\$` first matches `regex\$`
`inner` (`a#`, `b#`) – inner product
`invBinomialP` (`P`, `k`, `n`) – inverse of `binomialP`
`invBinomialQ` (`Q`, `k`, `n`) – inverse of `binomialQ`
`invChiSquareQ` (`q`, `df`) – inverse of `chiSquareQ`
`invFisherQ` (`q`, `df1`, `df2`) – inverse of `fisherQ`
`invGaussQ` (`z`) – inverse of `gaussQ`
`invSigmoid` (`x`) – inverse `sigmoid`
`invSigmoid#` (`vector#`) – inverse sigmoid of each element of `vector#`
`invSigmoid##` (`matrix##`) – inverse sigmoid of each cell of `matrix##`
`invStudentQ` (`q`, `df`) – inverse studentQ
`label` – place in a script to jump to
`left\$` (`string\$`, `n`) – the n first characters in `string\$`
`length` (`string\$`) – number of Unicode characters in `string\$`
`ln` (`x`) – natural logarithm, base e
`ln#` (`vector#`) – natural logarithm of each element of `vector#`
`ln##` (`matrix##`) – natural logarithm of each cell of `matrix##`
`lnGamma` (`x`) – logarithm of the Γ function
`log2` (`x`) – logarithm, base 2
`log2#` (`vector#`) – base-2 logarithm of each element of `vector#`
`log2##` (`matrix##`) – base-2 logarithm of each cell of `matrix##`
`log10` (x) – logarithm, base 10
`log10#` (`vector#`) – base-10 logarithm of each element of `vector#`
`log10##` (`matrix##`) – base-10 logarithm of each cell of `matrix##`
`max` (`x`, `...`) – maximum
`mean` (`v#`) – average of the elements of a vector
`melToHertz` (`x`) – from mel to acoustic frequency
`mid\$` (`string\$`, `from`, `n`) – the `n` characters in `string\$` starting at position `from`
`min` (`x`, `...`) – minimum
`minusObject` (`...`) – shrink the selection of objects in the list
`mul##` (`a##`, `b##`) – matrix multiplication
`number` (`a\$`) – interpret a string as a number
`number#` (`a\$#`) – interpret strings as numbers
`numberOfColumns` (`matrix##`)
`numberOfRows` (`matrix##`)
`outer##` (`a#`, `b#`) – outer product, i.e. resultij = aibj
`pauseScript` (`...`) – show a message in a simple pause window
`percent\$` (`number`, `precision`) – format a number as a string, with a trailing percent sign and `precision` digits after the decimal point
`phonToDifferenceLimens` (`x`) – from perceptual loudness to jnd-scale
`plusObject` (`...`) – extend the selection of objects in the list
`procedure`: `procedureName`, `...` – start a procedure definition
`randomBernoulli` (`p`) – Bernoulli-distributed random deviate (0 or 1)
`randomBernoulli#` (`n`, `p`) – `n` independent Bernoulli-distributed zeroes and ones
`randomGamma` (`shape`, `rate`) – gamma-distributed random deviate
`randomGamma#` (`n`, `shape`, `rate`) – n independent gamma-distributed random numbers
`randomGamma#` (`vector#`, `shape`, `rate`) – duplicate `vector#`, and replace all elements with independent gamma-distributed random numbers
`randomGamma##` (`nrow`, `ncol`, `shape`, `rate`) – nrow × ncol independent gamma-distributed random numbers
`randomGamma##` (`matrix##`, `shape`, `rate`) – duplicate `matrix##`, and replace all cells with independent gamma-distributed random numbers
`randomGauss` (`mu`, `sigma`) – normally distributed random deviate
`randomGauss#` (`n`, `mu`, `sigma`) – n independent normally distributed random numbers
`randomGauss#` (`vector#`, `mu`, `sigma`) – duplicate `vector#`, and replace all elements with independent normally distributed random numbers
`randomGauss##` (`nrow`, `ncol`, `mu`, `sigma`) – `nrow` × `ncol` independent normally distributed random numbers
`randomGauss##` (`matrix##`, `mu`, `sigma`) – duplicate `matrix##`, and replace all cells with independent normally distributed random numbers
`randomInteger` (`min`, `max`) – uniformly distributed integer random deviate
`randomInteger#` (`n`, `min`, `max`) – `n` independent uniformly distributed random integers
`randomInteger#` (`vector#`, `min`, `max`) – duplicate `vector#`, and replace all elements with independent uniformly distributed random integers
`randomInteger##` (`nrow`, `ncol`, `min`, `max`) – `nrow` × `ncol` independent uniformly distributed random integers
`randomInteger##` (`matrix##`, `min`, `max`) – duplicate `matrix##`, and replace all cells with independent uniformly distributed random integers
`randomPoisson` (`mean`) – Poisson-distributed random deviate
`randomPoisson#` (`n`, `mean`) – `n` independent Poisson-distributed random numbers
`randomPoisson#` (`vector#`, `mean`) – duplicate `vector#`, and replace all elements with independent Poisson-distributed random numbers
`randomPoisson##` (nrow, ncol, `mean`) – `nrow` × `ncol` independent Poisson-distributed random numbers
`randomPoisson##` (`matrix##`, `mean`) – duplicate `matrix##`, and replace all cells with independent Poisson-distributed random numbers
`randomUniform` (`min`, `max`) – uniformly distributed random deviate
`randomUniform#` (`n`, `min`, `max`) – n independent uniformly distributed random numbers
`randomUniform#` (`vector#`, min, max) – duplicate `vector#`, and replace all elements with independent uniformly distributed random numbers
`randomUniform##` (`nrow`, `ncol`, `min`, `max`) – `nrow` × `ncol` independent uniformly distributed random numbers
`randomUniform##` (`matrix##`, `min`, `max`) – duplicate `matrix##`, and replace all cells with independent uniformly distributed random numbers
`random_initializeSafelyAndUnpredictably` ( ) – undoes the effects of the following function
`random_initializeWithSeedUnsafelyButPredictably` (`seed`) – reproducible sequence of random numbers
`readFile` (`filePath\$`) – read a number from a text file
`readFile\$` (`filePath\$`) – read a whole text file into a string
`readFile#` (`filePath\$`) – read a vector from a text file
`readFile##` (`filePath\$`) – read a matrix from a text file
`readLinesFromFile\$#` (`filePath\$`) – read all lines from a text file
`rectify` (`x`) – set to zero if negative (no change if positive)
`rectify#` (`vector#`) – rectify each element of `vector#`
`rectify##` (`matrix##`) – rectify each cell of `matrix##`
`removeObject` (`...`) – remove objects from the list, by ID and/or name
`repeat#` (`v#`, `n`) – repeat the whole sequence of elements of `v#` `n` times
`replace\$` (`a\$`, `b\$`, `c\$`, `n`) – within `a\$`, replace the first `n` occurrences of `b\$` with `c\$`, or all if `n` = 0
`replace_regex\$` (`a\$`, `b\$`, `c\$`, `n`) – within `a\$`, replace the first `n` matches of regular expression `b\$` with the regular expression `c\$`, or all if `n` = 0
`right\$` (`string\$`, `n`) – the n last characters in `string\$`
`rindex` (`string\$`, `part\$`) – look up a substring from the end, or 0 if not found
`rindex` (`strings\$#`, `s\$`) – look up whether and where `s\$` last occurs in `strings\$#`
`rindex_regex` (`string\$`, `regex\$`) – determine whether and where `string\$` last matches `regex\$`
`round` (`x`) – nearest integer
`round#` (`vector#`) – nearest integer of each element of `vector#`
`round##` (`matrix##`) – nearest integer of each cell of `matrix##`
`rowSums#` (`matrix##`)
`runScript` (`filePath\$`, `...`) – run a script with the given arguments
`runSubprocess` (`executableFilePath\$`, `...`) – run an external program with the given arguments
`runSubprocess\$` (`executableFilePath\$`, `...`) – run an external program with the given arguments, and return its output
`runSystem` (`...`) – run a system command line with the given arguments concatenated
`runSystem\$` (`...`) – run a system command line with the given arguments concatenated, and return its output
`selected#` ( ) – the IDs of all selected objects
`selected#` (`type`) – the IDs of all selected objects of type `type`
`selected\$#` ( ) – the names of all selected objects
`selected\$#` (`type`) – the names of all selected objects of type `type`
`selectObject` (`...`) – select objects in the list by ID and/or name
`semitonesToHertz` (`x`) – from logarithmic scale re 100 Hz to acoustic frequency
`sigmoid` (`x`) – 1 / (1 + e-`x`)
`sigmoid#` (`vector#`) – sigmoid of each element of `vector#`
`sigmoid##` (`matrix##`) – sigmoid of each cell of `matrix##`
`sin` (`x`) – sine
`sin#` (`vector#`) – sine of each element of `vector#`
`sin##` (`matrix##`) – sine of each cell of `matrix##`
`sinc` (`x`) – sinus cardinalis: sin (`x`) / `x`
`sincpi` (`x`) – sin (πx) / (πx)
`sinh` (`x`) – hyperbolic sine
`sinh#` (`vector#`) – hyperbolic sine of each element of `vector#`
`sinh##` (`matrix##`) – hyperbolic sine of each cell of `matrix##`
`size` (`v#`) – number of elements
`shuffle#` (`vector#`) – randomize order
`shuffle\$#` (`stringVector\$#`) – randomize order
`sleep` (`duration`) – pause script for `duration` seconds
`softmax#` (`vector#`)
`softmaxPerRow##` (`matrix##`)
`solve#` (`a##`, `y#`) – find x for which A · x = y
`solve##` (`a##`, `y##`) – find X for which A · X = Y
`solveNonnegative#` (`a##`, `y#` [, `x`], `maximumNumberOfIterations`, `tolerance`, `infoLevel`)
`solveSparse#` (`a##`, `y#` [, `x`], `maximumNumberOfNonzeros`, `maximumNumberOfIterations`, `tolerance`, `infoLevel`)
`solveWeaklyConstrained#` (`a##`, `y#`, `alpha`, `delta`)
`sort#` (`vector#`) – reshuffle in increasing order
`sort\$#` (`stringVector\$#`) – reshuffle in Unicode-alphabetical order
`sort_numberAware\$#` (`stringVector\$#`) – reshuffle in Unicode-alphabetical order, with special attention to numbers
`splitByWhitespace\$#` (`string\$`) – split a string into inks
`sqrt` (`x`) – square root
`sqrt#` (`vector#`) – square root of each element of `vector#`
`sqrt##` (`matrix##`) – square root of each cell of `matrix##`
`startsWith` (`string\$`, `part\$`) – determine whether `string\$` starts with `part\$`
`stdev` (`v#`) – standard deviation of the elements of a vector
`stopwatch` – give the current value of the timer, which is then immediately reset to zero (note: no parentheses)
`string\$` (`number`) – format a number as a string
`studentP` (`t`, `df`) – area under the Student T curve up to `t`
`studentQ` (`t`, `df`) – area under the Student T curve after `t`
`sum` (`v#`) – sum the elements
`sumOver` (`loopVariable` `to` `n`, `numericExpressionOptionallyUsingLoopVariable`) – Σ
`tan` (`x`) – tangent
`tan#` (`vector#`) – tangent of each element of `vector#`
`tan##` (`matrix##`) – tangent of each cell of `matrix##`
`tanh` (`x`) – hyperbolic tangent
`tanh#` (`vector#`) – hyperbolic tangent of each element of `vector#`
`tanh##` (`matrix##`) – hyperbolic tangent of each cell of `matrix##`
`to#` (`n`) – the integers 1 through `n`
`transpose##` (`matrix##`) – flip matrix along its diagonal
`tryToAppendFile` (`filePath\$`) – check whether a file can be appended to
`tryToWriteFile` (`filePath\$`) – check whether a file can be written (destructive!)
`unicode` (`c\$`) – the Unicode codepoint number that corresponds to character `c\$`
`unicode\$` (`n`) – the character that corresponds to Unicode codepoint `n`
`unicodeToBackslashTrigraphs\$` (`string\$`) – convert e.g. ɔ to \ct
`variableExists` (`variableName\$`) – does the variable `variableName\$` exist?
`vertical\$` (`stringArray\$#`) – format a string array vertically
`writeFile` (`filePath\$`, `...`) – create a new text file, and write texts, numbers, vectors and so on into it
`writeFileLine` (`filePath\$`, `...`) – create a new text file, write texts, numbers, vectors and so on into it, followed by a newline
`writeInfo` (`...`) – write texts, numbers, vectors and so on, to a clear Info window
`writeInfoLine` (`...`) – write texts, numbers, vectors and so on, followed by a newline, to a clear Info window
`zero#` (`n`) – vector with `n` elements that are all 0
`zero##` (`nrow`, `ncol`) – matrix with `nrow` × `ncol` elements that are all 0