Reputation: 11
I have a data set of coordinates (X,Y) values in the Cartesian plane and I would like to find the RMSE of these points to 1 coordinate (x1,y1). So basically, (X,Y) are around (x1,y1) and I would like to find their RMSE.
Could anyone help me because I'm not sure I'm doing this right:
I'm doing this:
Err = Err + sqrt[(X(i) - x1)^2 + (Y(i) - y1)^2] - - - - Previous error + current error (Distance between points)
RMSE = sqrt[(1/no_Of_Points)*Err^2]
Is this correct?
I am doing this in MATLAB so feel free write code if you need.
This is my code:
RMSEright = 0;
countright = 0;
for i = 1:1:size(VarName1,1)
[x,y] = pol2cart(VarName2(i,1), VarName1(i,1));
if x > 0
RMSEright = RMSEright + (((featureright(1,1) - x)^2)+((featureright(1,2) - y)^2))^0.5;
countright = countright + 1;
end
end
RMSEright = ((1/countright)*RMSEright)^0.5
Thank you!
Upvotes: 1
Views: 3572
Reputation: 1550
I can see in your code that you are interested in measuring the RMSE of the points at the right of the center x_center
, the points where x(1) > x_center(1)
.
You can vectorize this and avoid using a loop. Let z = z = [X Y];
, then z = z(z(:,1) > z_center(1), :);
Then, to compute RMSE, sqrt(mean(vecnorm(z-z_center, 2, 2).^2))
.
Here is a sample code:
% Center point
z_center = [1 1];
plot(z_center(1), z_center(2),'r*'); hold on;
% Data Points
X = [1.2256; 1.2931; 0.1213; 1.0387; 0.5158; 1.5895; 1.1485; 1.5914; 0.6550; 0.8026];
Y = [0.9002; 0.2724; 1.0856; 0.0871; 1.2780; 0.8944; 0.9888; 0.3219; 1.2895; 1.0577];
z = [X Y];
plot(z(:,1), z(:,2),'*');
% Select "right" points
z = z(z(:,1) > z_center(1), :);
% Compute RMSE
sqrt(mean(vecnorm(z-z_center, 2, 2).^2))
plot(z(:,1), z(:,2),'oc');
legend('center', 'points', 'right points');
It returns
ans = 0.6710
And plots
Upvotes: 1