# could anyone help me how to compute the mean square error between two cell.

3 views (last 30 days)
jaah navi on 17 Jul 2021
Commented: jaah navi on 19 Jul 2021
I am having two cell A and B in the attached data.mat.
I want to compute the mean square error between A and B in data.mat.
##### 2 CommentsShowHide 1 older comment
jaah navi on 17 Jul 2021
Here, both A and B has the same N-by-2 vector, for example
A{1,1}
1 2
1 1
1 1
1 1
1 2
1 1
1 2
1 2
1 2
1 2
B{1,1}
1 1
1 2
1 1
1 1
1 1
1 1
1 2
1 2
1 2
1 1
So first column of A needs to get subtracted with first column of B denoted by C and second column of A needs to get subtracted with second column of B denoted by D. Then I need to find the difference between C and D, square it and add all the rows and divide it by the 10.

Walter Roberson on 17 Jul 2021
cellfun(@(a,b) sqrt(sum(a(:)-b(:)).^2))
You had the wrong definition of mean square error.
Walter Roberson on 18 Jul 2021
Please show the output of the following:
cellfun(@(a)string(class(a)), A)
cellfun(@(a)string(class(a)), B)
I suspect your A and B are not cell array of double like you indicate here. Judging by some of your other posts, I suspect that you have a mix, that some of the entries are double and others are cell.

### More Answers (1)

jaah navi on 18 Jul 2021
Anyhow i managed to get the partial output as required using the following commands for my data.mat as attached.
C=cellfun(@minus,A,B,'UniformOutput',false);
D=cellfun(@(x) sum((x(:,1)-x(:,2)).^2)/10,C,'UniformOutput',false)
Now I want to sum up all the rows of D and divide it by 5.
jaah navi on 19 Jul 2021
Thanks.