How to take RMS of every 10 values in a matrix and output this?

1 view (last 30 days)
I have a matrix of 66,000 x 4 and am needing to take an RMS of every 10 values, reducing it to 6600 x 4. I am not sure the best way to code this so any help greatly appreciated. It is to allow me to perform some signal processing and compare to another matrix. Thanks in advance!

Accepted Answer

Star Strider
Star Strider on 16 Mar 2018
Try this:
A = randi(9, 66000, 4); % Create Matrix
Ar = reshape(A, [], 4, 10); % Reshape
A_RMS = sqrt(mean(Ar.^2, 3)); % Calculate RMS
  3 Comments
Star Strider
Star Strider on 21 Mar 2018
As always, my pleasure!
If my Answer helped you solve your problem, please Accept it!
Akira Agata
Akira Agata on 22 Mar 2018
Something weird...
Please try the following as an input A. In this case, every 4 columns are the same, so every 4 columns of A_RMS should be also the same. But the result is not.
A = repmat(randi(9, 66000, 1),1,4);

Sign in to comment.

More Answers (1)

Akira Agata
Akira Agata on 22 Mar 2018
Another possible solution:
A = randi(9, 66000, 4); % Sample matrix
g = repelem([1:6600]',10); % Create group ID
func = @(x) sqrt(mean(x.^2)); % RMS function
A_RMS = splitapply(func,A,g); % Apply RMS function for each group

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!