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
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 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by