function [y] = rms3(v)
% Root mean square
% rms3(v) returns the root mean square of the 
% elements of the vector v. If v is a matrix, 
% then rms(v) returns a row vector such that each element
% is the root mean square of the elements in the corresponding
% column of v.
% BJ Furman
% 30APR2012

% test that v does not have greater size than a matrix
size_arg=size(v);
if (length(size_arg) > 2)
	fprintf('Error in size of array argument - must be a matrix or vector\n')
	return
else
% we either have a matrix or vector

% test if v is a row vector. Transpose if so.
	if (size_arg(1) == 1)
		v=v';
		size_arg=size(v);	% update the size vector
    end
% calculate rms for row vector(s)
	vs = v.^2;   % square the elements
	y = sqrt(sum(vs)/size_arg(1)); % sums elements in each column and divides by column length

end