View Raw SPL
/*****************************************************************************
* *
* VMEAN.SPL Copyright (C) 2014 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Returns the mean of one or more input arguments *
* *
* Revisions: 22 Sep 2014 RRR Creation *
* *
*****************************************************************************/
#if @HELP_VMEAN
VMEAN
Purpose: Returns the scalar mean of one or more input arguments.
Syntax: VMEAN(val1, val2, ..., valN)
valN - One ore more series or scalars.
Returns: A real, the mean of all the input values.
Example:
vmean(10, 15, 20)
returns 15
Example:
vmean({1, 2, 3, 4, 5}, {1, 4, 2}, {1, 0, 3, 8})
returns 2.833333
Example:
W1: gsin(100, 1/100, 1)^2
W2: gcos(1000, 1/1000, 1)^2
W3: gline(200, 1/200, 1, 0)
W4: concat(W1, W2, W3)
a = mean(W4);
b = vmean(W1, W2, W3);
a == b == 0.499615
Example:
W1: ravel(1..9, 3)
W2: {mean(W1)}
W3: {vmean(w1)}
W1 == {{1, 4, 7},
{2, 5, 8},
{3, 6, 9}}
W2 == W3 == 5
Remarks:
VMEAN with no input arguments uses the current Window.
Non-numeric arguments are ignored.
See VAVGS to compute the point by point mean of the input values.
See VSUM to compute the scalar sum of the input values.
See Also:
Avgs
Mean
Vavgs
Vmax
Vmin
Vsum
#endif
/* scalar mean of input args */
vmean(argv)
{
local j, cnts, sums, s;
if (argc < 1)
{
/* return mean of current window */
return(mean(w0));
}
cnts = 0;
sums = 0;
/* get sum and lengths of inputs */
loop (j = 1..argc)
{
if (isnumeric(getargv(j)))
{
s = isarray(getargv(j)) ? refseries(getargv(j)) : castseries(getargv(j));
/* assume series is multi-column */
sums += sum(colsum(s)');
cnts += sum(collength(s)');
}
}
/* mean */
return(sums / cnts);
}