How do I calculate mean absolute error?

78 views (last 30 days)
x_T = 0.3; y_T = 0.3;
A_T = 38:0.1:45;
for i_A = 1:length(A_T)
for i_file = meas
error_1(i_file,:) = sqrt((x_T_est1(i_file,:) - x_T).^2 + (y_T_est1(i_file,:) - y_T).^2);
end
end
Hello everyone. I am sharing part of my code. I am also attaching the necessary files.
What I want to do is adapt this formula. The number n is the size of the matrix x_T_est1 an y_T_est1. So 28x5=140. n = 140.
I want to calculate MAE for all numbers in matrix x_T_est1. But I want to save it in a matrix of length i_A.
In summary, subtract the x_T and y_T values for all the elements in the x_T_est1 matrix, take the square root, and add the value for all the elements. Then divide by 140. This result is a number. For example, let the result be the number A. Let it record this number A as the length of the matrix A_T. So the result vector and the vector A_T will be the same size. Result matris = A, A, A...(1x71). Vector A_T is a vector of length 1x71.
You can change the code however you want.

Accepted Answer

David Hill
David Hill on 6 Apr 2022
Edited: David Hill on 7 Apr 2022
x_T = 0.3; y_T = 0.3;
%A_T = 38:0.1:45; have no idea what you are doing with A_T (it is not in your equation)
[x,y]=meshgrid(x_T_est1,y_T_est1);
mae=sum(sqrt((x_T-x).^2+(y_T-y).^2)./numel(x),'all');%this is the mae for the x_T and y_T values listed
  2 Comments
studentmatlaber
studentmatlaber on 6 Apr 2022
I didn't share the whole code here. However, A_T has a task like this. The matrix x_T_est1 is calculated as much as the number of A_T. So the matrix x_T_est1 is created 71 times. My goal here is to keep the MAE calculated from each different matrix x_T_est1 in a matrix.
When I try your code I get an error like this.
Error using sum
Invalid option. Option must be 'double', 'native', 'default', 'omitnan', or 'includenan'.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!