root mean square error in matlab

To calculate the Root Mean Square Error (RMSE) in MATLAB, you can use the following code:

main.m
% true values
y_true = [1, 2, 3, 4, 5];

% predicted values
y_pred = [1.5, 2.5, 2.8, 3.7, 5.2];

% calculate RMSE
rmse = sqrt(mean((y_true - y_pred).^2))

% output the RMSE
disp(rmse)
184 chars
12 lines

In this example, y_true represents the true values and y_pred represents the predicted values. The mean function is used to calculate the mean of the squared differences between the true and predicted values, and the sqrt function is used to take the square root of this value, resulting in the RMSE. The output of this example will be:

main.m
rmse =
    0.6164
18 chars
3 lines

This means that the RMSE between y_true and y_pred is approximately 0.6164.

gistlibby LogSnag