med

From DavinciWiki
Jump to: navigation, search

Description

The function med() computes the statistical median along one or more axes. If no axis is specified, then the median is computed along all three.

Arguments and Return Values

Arguments: A numeric matrix, and optional arguments specifying a value to ignore and the axis/axes along which to find the median

Return Value: An array whose values give the median of the input along the specified axis

Usage

Syntax: med(matrix[, axis="string"][, ignore=value])

matrix - The array for which to find the median

axis - A string specifying whether to take the median along x, y, z, or a combination. It MUST be a string, due to the limitations of user-defined functions. The returned array will have a dimension of one along whichever axes are specified in axis. If using multiple axes, they must be in alphabetical order, so "xy" is fine, but "yx" will not be recognized.

ignore - A scalar (number) specifying a value to exclude from computations. If not specified, no value is ignored. If all elements of a subset are equal to ignore, the ignore value is put in the corresponding element of the output.

If possible, the format of the output is the same as the format of the input. However, in some cases, that would involve a loss of accuracy (see final example), so the returned array will be double and a warning will be displayed.

If med() is entered with no arguments, it prints its description, as shown below.

Examples

dv> med()

Computes median of a data set
med(data, axis="x"|"y"|"z"|"xy"|"xz"|"yz"|"xyz", ignore=value)
 The inputs axis and ignore are both optional. If used, each must
  be passed by reference.
 axis specifies the axis/axes of the array along which to compute
  the median. It must be entered as a string. If no axis is
  specified (or if axis="xyz", the returned value is the median
  of the entire array.
 ignore specifies the value to exclude from computations. If all
  elements are equal to ignore, the function returns ignore.
For a data set (or subset) with an even number of points, it
 returns the mean of the two middle points.
S.Marshall 12-04-2010

dv> a
3x3x1 array of int, bsq format [36 bytes]
1       2       3
4       4       4
7       8       9
dv> med(a)
4
dv> med(a, axis="x")
1x3x1 array of int, bsq format [12 bytes]
2
4
8
dv> med(a, axis="y")
3x1x1 array of int, bsq format [12 bytes]
4       4       4
dv> med(a, axis="z")
3x3x1 array of int, bsq format [36 bytes]
1       2       3
4       4       4
7       8       9
dv> med(a, axis="xy")
4
dv> med(a, ignore=4)
5
dv> b
3x1x1 array of int, bsq format [12 bytes]
1       2       4
dv> med(b)
2
dv> med(b, ignore=2)

Cannot convert output back to input format without a loss of accuracy
2.50000000000000

DavinciWiki Mini-Nav Bar

Contents


Contact Developers

  • davinci-dev [AT] mars.asu.edu

All other topics

  • See navigation on the left

Related Functions

Recent Library Changes

Created On: 12-02-2010
Modified On: 12-05-2010

Personal tools