Implement an equation with a substraction and division of two arrays

1 view (last 30 days)
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?

Accepted Answer

Sara Alonso Vicario
Sara Alonso Vicario on 7 Apr 2021
Edited: Sara Alonso Vicario on 7 Apr 2021
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)

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!