Implement an equation with a substraction and division of two arrays

1 vue (au cours des 30 derniers jours)
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?

Réponse acceptée

Sara Alonso Vicario
Sara Alonso Vicario le 7 Avr 2021
Modifié(e) : Sara Alonso Vicario le 7 Avr 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)

Plus de réponses (0)

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by