MATLAB CODE FOR ROOT MEAN SQUARED
11 ビュー (過去 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);
0 件のコメント
採用された回答
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 件のコメント
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
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()
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!