Implement an equation with a substraction and division of two arrays

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Sara Alonso Vicario
Sara Alonso Vicario el 7 de Abr. de 2021
Editada: Sara Alonso Vicario el 7 de Abr. de 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)

Más respuestas (0)

Categorías

Más información sobre Array Geometries and Analysis en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by