How do I calculate mean absolute error?

조회 수: 75 (최근 30일)
studentmatlaber
studentmatlaber 2022년 4월 6일
댓글: David Hill 2022년 4월 7일
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.

채택된 답변

David Hill
David Hill 2022년 4월 6일
편집: David Hill 2022년 4월 7일
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
studentmatlaber
studentmatlaber 2022년 4월 6일
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
David Hill 2022년 4월 7일
Sorry, try it now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by