Implement an equation with a substraction and division of two arrays

조회 수: 1 (최근 30일)
I want to implement this equation in Matlab
The a values are in an array of 140x1 double called approx, the values of x are also in an array of 140x1 double called subArray, and n is an array 1x1 with a value equal to 140.
I am using the following code:
MRE=(1/n)*(abs(approx(:,1)- subArray(:,1))/abs(subArray(:,1)));
but Im getting the following error
Unable to perform assignment because the left and right sides have a different number of elements.
How could I implement this equation in Matlab?

채택된 답변

Sara Alonso Vicario
Sara Alonso Vicario 2021년 4월 7일
편집: Sara Alonso Vicario 2021년 4월 7일
Here you want element-wise division. Also don't forget the summation:
MRE = (1/n) * sum((abs(approx - subArray) ./ abs(subArray)));
^^^ ^
Using some random data:
clc, clear, rng(3);
n = 140;
approx = rand(n, 1);
subArray = rand(n, 1);
MRE = (1/n) * sum((abs(approx - subArray) ./ abs(subArray)))
% MRE =
%
% 4.2877
(answer by the user tdy in stackoverflow)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Array Geometries and Analysis에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by