MATLAB CODE FOR ROOT MEAN SQUARED

12 vues (au cours des 30 derniers jours)
Grace
Grace le 13 Sep 2022
Modifié(e) : Torsten le 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);

Réponse acceptée

Torsten
Torsten le 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 commentaires
Grace
Grace le 13 Sep 2022
Hi Torsten, It does not work, still woth
cal_rms(row) = sqrt((MEAN-M(row, :)).^2./columns);
Torsten
Torsten le 13 Sep 2022
Modifié(e) : Torsten le 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)

Connectez-vous pour commenter.

Plus de réponses (1)

Bruno Luong
Bruno Luong le 13 Sep 2022
Modifié(e) : Bruno Luong le 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

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by