MSE and RMSE of a matrix

60 views (last 30 days)
Sadiq Akbar
Sadiq Akbar on 3 Oct 2020
Commented: KSSV on 4 Oct 2020
I have a reference vector u of size 1x8. In this matrix the 1st four columns are voltage readings and last four columns are current readings.i.e.
u=[v1 v2 v3 v4 i1 i2 i3 i4];
Likewise I have another set of 100 vectors.The size of each of them is also 1x8. The nature of those vectors is also same like u i.e. 1st four columns are voltages and last four columns are currents in each of them. If I write those 100 vectors in a matrix called two. The size of the matrix two becomes 100x8. Now I find the difference between each of the row of matrix two and u. i.e.This gives me another matrix Error of size 100x8. i.e.
Error(nn,:)= abs(u(1,:)-two(nn,:));
Now I want to find the MSE and RMSE of this matrix Error and plot both the MSE and RMSE.
  1 Comment
Sadiq Akbar
Sadiq Akbar on 3 Oct 2020
This is my code. Is this correct?
u=[1 1.5 2 2.5 150 20 60 110];
two=randi(100,8);
for nn=1:100
Error(nn,:)= abs(u(1,:)-two(nn,:));
Error4sn0(nn)=abs(Error(nn,:)).^2; % Sqaured Error of Four sources
MSE4sn0(nn) = sum(Error4sn0(nn,:))/8;
end
MSE4sn0=MSE4sn0';
MSE4sn0=sort(MSE4sn0,'descend');
t=1:100;
semilogy(t,smooth(MSE4sn0),'linewidth',2)
xlabel('Runs')
ylabel('MSE')
title('MSE of All ')

Sign in to comment.

Answers (1)

KSSV
KSSV on 3 Oct 2020
If yt and ye are the column vectors of theory and experimental values. You can get MSE, RMSE using:
e = (ye - yt) % Errors
suqre_e = (ye - yt).^2 % Squared Error
MSE = mean((ye - yt).^2) % Mean Squared Error
RMSE = sqrt(mean((ye - yt).^2)); % Root Mean Squared Error
  8 Comments
Sadiq Akbar
Sadiq Akbar on 3 Oct 2020
Thank you very much for your help. I used the plot command directly, but it gave me the following error:
Error using plot
Vectors must be the same length.
Error in MSERMSEbyKSSV (line 12)
plot(t,MSE,t,RMSE);
KSSV
KSSV on 4 Oct 2020
Check the sizes of t , MSE.

Sign in to comment.

Categories

Find more on Line Plots 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!