how to find the difference between first column and second column in a cell array

I am a having cell
C=5x1 cell
which contains
10x2 double
10x2 double
10x2 double
10x2 double
10x2 double
I need to find the difference between first and second column of C. Could anyone please help me on it.

 Accepted Answer

cellfun(@(x) x(:,1)-x(:,2),C,'UniformOutput',false)

5 Comments

ok. As a next step I calculated the sum using
cellfun(@sum, C,'UniformOutput',false)
Now I want to divide by 10.
So i tried using
cellfun(@sum, C,'UniformOutput',false)/10
but i am getting error stating Undefined operator '/' for input arguments of type 'cell'.
Could you please help me to overcome the error.
If you do the sum and then divide by 10, so I guess you want to calculate the mean and you can use the following directly without doing the sum
cellfun(@mean,previous_result,'UniformOutput',false)
Sorry, I made a mistake. First I need to square it and then sum it together and divide by 10. Could you please help me on it.
I used the command
D=cellfun(@(x) sum((x(:,1)-x(:,2)).^2)/10,C,'UniformOutput',false)
Now I want to sum D and divide by 5.
Could you please help me on this.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 18 Jul 2021

Commented:

on 18 Jul 2021

Community Treasure Hunt

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

Start Hunting!