rms
Root mean square value.
📝Syntax
Y = rms(X)
Y = rms(X, DIM)
Y = rms(X, VECDIM)
Y = rms(X, "all")
Y = rms(..., TYPE)
Y = rms(..., NANFLAG)
📥Input Arguments
Parameter Description
X input data: single, double, logical or integer.
DIM dimension to operate along.
VECDIM vector of dimensions to operate along.
"all" operate on every element of X.
TYPE class of the result: "default", "double" or "native".
NANFLAG "includenan" or "omitnan". "includemissing" and "omitmissing" are also accepted.
📤Output Arguments
Parameter Description
Y root mean square values.
📄Description

rms computes sqrt(mean(abs(X) .^ 2)) along the selected dimension:

$$\mathrm{RMS}(X) = \sqrt{ \frac{1}{N} \sum_{n=1}^{N} |x_n|^2 }$$

where N is the number of elements along that dimension.

Class of the result: the square and the mean always run in double, so an integer input never saturates. "native" returns the class of the input, "double" returns double, and "default" returns double for an integer input and the class of the input otherwise. A logical input is not an integer class and returns double.

Missing values: NaN values are included by default. Use "omitnan" or "omitmissing" to leave them out.

💡Examples
root mean square of a vector
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t);
y = rms(x)
% y = 0.7071
one value per column
x = [4 -5 1; 2 3 5; -9 1 7];
y = rms(x)
% y = [5.8023 3.4157 5.0000]
one value per row
x = [6 4 23 -3; 9 -10 4 11; 2 8 -5 1];
y = rms(x, 2)
% y = [12.1450; 8.9163; 4.8477]
leaving missing values out
x = [1.77 -0.005 nan -2.95; nan 0.34 nan 0.19];
y = rms(x, "omitnan")
% y = [1.7700 0.2404 nan 2.0903]
integer input with a native result
M = uint8([10:30:70; 20:30:80; 30:30:90]);
R = rms(M, 'native')
% R = uint8([22 51 80])
D = rms(M)
% D = [21.6025 50.6623 80.4156]
🔗See Also
peak2peakmaxmin
🕔Version History
Version Description
1.16.0 initial version
Edit this page on GitHub