MATLAB CODE FOR ROOT MEAN SQUARED
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
0 Kommentare
Akzeptierte Antwort
Torsten
am 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 Kommentare
Torsten
am 13 Sep. 2022
Bearbeitet: Torsten
am 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)
Weitere Antworten (1)
Bruno Luong
am 13 Sep. 2022
Bearbeitet: Bruno Luong
am 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()
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!