MSE and RMSE of vector and Matrix
4 views (last 30 days)
Show older comments
I have a vector u=[-30 0 41.721]; and a matrix two=rand(100,3); I want to find the error between the two, square of that error, mean square error and root mean square error for all 100 values. How can I find them. After that I want to plot the error vs ii=1:100, square of error vs ii=1:100 and mean square error vs ii=1:100 and root mean square error vs ii=1:100. I tried like this but it gives error:
clear all
clc
u=[-30 0 41.721];
two=rand(100,3);
[m,n] = size(two) ;
Error = abs(u-two) ;
square_Error = abs(u-two).^2 ;
for ii=1:m
MSE(ii) = norm((u-two(ii,:)).^2/m); %MSE = (u-two).^2/m ;
RMSE(ii) = sqrt((u - two(ii,:)).^2/m);
end
MSE=MSE';
RMSE=RMSE';
plot(ii,MSE,'r',ii,RMSE,'g')
0 Comments
Accepted Answer
DGM
on 11 Oct 2022
You're not taking the mean of the row vectors, so the RHS of the assignment is still a vector. Try this:
u = [-30 0 41.721];
two = rand(100,3);
[m,n] = size(two);
MSE = mean((u-two).^2,2);
RMSE = sqrt(MSE);
x = 1:m;
plot(x,MSE,'r',x,RMSE,'g')
More Answers (0)
See Also
Categories
Find more on NaNs 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!