# How do I calculate mean absolute error?

60 visualizzazioni (ultimi 30 giorni)
studentmatlaber il 6 Apr 2022
Commentato: David Hill il 7 Apr 2022
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.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

David Hill il 6 Apr 2022
Modificato: David Hill il 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 CommentiMostra NessunoNascondi Nessuno
studentmatlaber il 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'.
David Hill il 7 Apr 2022
Sorry, try it now.

Accedi per commentare.

### Categorie

Scopri di più su Matrix Indexing in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by