MATLAB CODE FOR ROOT MEAN SQUARED

14 views (last 30 days)
Grace
Grace on 13 Sep 2022
Edited: Torsten on 13 Sep 2022
Hello,please I have a matrix M, containng three distinct sets of data, and I intend to calculate the root mean squared. Coiuld some kinndly assist me; here is my trial code
clear all;close all;clc
A=[2 4 7 10 28]; %first
B=[1 3.6 8 11 27];%seccond
C=[0.5 5 9.5 13 32];%third
M=[A' B' C'];
[rows, columns] = size(M);
MEAN=zeros(rows, columns);
for row = 1 : rows
MEAN(row) = mean(M(row, :));
cal_rms=sqrt((MEAN-M(row, :)).^2./columns);
end
plot(cal_rms);

Accepted Answer

Torsten
Torsten on 13 Sep 2022
This is not the standard definition for the root-mean-square value of a matrix.
Are you sure about the formula ? Then use
cal_rms(row) = sqrt((MEAN-M(row, :)).^2./columns);
instead of
cal_rms=sqrt((MEAN-M(row, :)).^2./columns);
  2 Comments
Grace
Grace on 13 Sep 2022
Hi Torsten, It does not work, still woth
cal_rms(row) = sqrt((MEAN-M(row, :)).^2./columns);
Torsten
Torsten on 13 Sep 2022
Edited: Torsten on 13 Sep 2022
MATLAB has a function "rms" for the rooot-mean-square value - you might want to use it, but it doesn't work with the matrix elements shifted by the mean value.
What you calculate is some kind of standard deviation of the rows of M, but in this case, you had to divide by (columns-1), not by (columns).
A=[2 4 7 10 28]; %first
B=[1 3.6 8 11 27];%seccond
C=[0.5 5 9.5 13 32];%third
M=[A.', B.', C.'];
[rows, columns] = size(M);
MEAN=zeros(rows,1);
for row = 1 : rows
MEAN(row) = mean(M(row, :));
cal_rms(row) = sqrt(sum((MEAN(row)-M(row,:)).^2)/columns);
end
plot(cal_rms)

Sign in to comment.

More Answers (1)

Bruno Luong
Bruno Luong on 13 Sep 2022
Edited: Bruno Luong on 13 Sep 2022
To my book the mean should not be removed in calculation of RMS
M = rand(3,100);
[rows, columns] = size(M);
cal_rms = zeros(rows,1);
for row=1:size(M,1)
cal_rms(row) = sqrt( sum(M(row, :).^2) / columns );
end
cal_rms % theoretical value is sqrt(1/3) for rand()
cal_rms = 3×1
0.5737 0.5854 0.5894

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!