1

Here's the function that I want to write out in MATLAB:

function

For my and y, I am using the indices of rm and m, respectively. Here's what I have so far:

mse = 1/n *(symsum(((rm{i}-m{i})^2),i,1,n));

I am getting this error:

Error in pcmencdec_hw2 (line 100)

mse = 1/n *(symsum(((rm{i}-m{i})^2),i,1,n));
Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
anime girl
  • 11
  • 1

1 Answers1

0

If Cell Arrays Storing Numerical Values

The cell arrays can be converted to MATLAB matrices/double arrays if they're storing numerical values. This conversion can be done by using the cell2mat() function. Element-wise subtracting can be done between these two arrays to find the difference between the corresponding elements (this will result in an array of differences the same length as rm and m). Taking the square root of these differences by squaring the elements, .^2 is the next step. The . indicates that the operation should be applied element-wise. Lastly, the sum is taken and multiplied by 1/N.

%Random test data%
rm = {rand(20000,1)};
m = {rand(20000,1)};

N = length(rm);

%Converting cell arrays to matrices/double arrays%
m = cell2mat(m);
rm = cell2mat(rm);

%Vectorized approach to calculating mean square error%
MSE = (1/N)*sum((rm - m).^2);
disp(MSE);
MichaelTr7
  • 4,737
  • 2
  • 6
  • 21