MATLAB CODE FOR ROOT MEAN SQUARED

14 次查看(过去 30 天)
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);

采纳的回答

Torsten
Torsten 2022-9-13
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 个评论
Grace
Grace 2022-9-13
Hi Torsten, It does not work, still woth
cal_rms(row) = sqrt((MEAN-M(row, :)).^2./columns);
Torsten
Torsten 2022-9-13
编辑:Torsten 2022-9-13
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)

请先登录,再进行评论。

更多回答(1 个)

Bruno Luong
Bruno Luong 2022-9-13
编辑:Bruno Luong 2022-9-13
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

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by