Calculating the mean per row of a nested cell arrays and/or RMSE of cell arrays
1 view (last 30 days)
Show older comments
I have a cell array:
A = 3×1 cell array
[14×122 double]
[14×395 double]
[14×424 double]
And cell:
B = 3×1 cell array
[14×122 double]
[14×395 double]
[14×424 double]
I need to calculate the RMSE of the first “within” row of A and the odd “within” rows of B. I am using the following equation:
RMSE = sqrt(mean((y - yhat).^2));
I have working:
cellfun(@(p) power(p,2),(cellfun(@(x,y) x(1,:) - y(1:2:end,:), test_Targets, Predicted_Targets,'uni', false)),'uni',false);
Which gives me the squared values of the difference of the rows I need. This returns a
ans = 3×1 cell array
[7×122 double]
[7×395 double]
[7×424 double]
Then, I am stuck at trying to calculate the mean. Technically, I need to do mean(C{i}(j,:)) but I was not have to implement it. I would like to have just one line for the whole RMSE. I tried
C=cellfun(@(x) power(x,2),(cellfun(@(x,y) x(1,:) - y(1:2:end,:), test_Targets, Predicted_Targets,'uni', false)),'uni',false);
j =cellfun(@(x) transpose(1:size(x,1)/2), Predicted_Targets,'uni',false);
cellfun(@(v,w) mean(v(w,:)), C,j,'uni',false)
ans = 3×1 cell array
[1×122 double]
[1×395 double]
[1×424 double]
Which is wrong because I am expecting a 3x1 containing 7x1 values.
At the end I would like to have something like:
RMSE = sqrt(arrayfun(@mean,cellfun(@(x) power(x,2),(cellfun(@(x,y) x(1,:) - y(1:2:end,:), test_Targets, Predicted_Targets,'uni', false)),'uni',false),'uni', false));
(This code is also wrong. It was my initial try before trying to implement the j. I also tried immse since it was suggested in another answer).
Thank you
1 Comment
dpb
on 30 Jun 2018
OK, so what is the actual computation you're trying to do; I got lost in the missteps along the way. I think if you illustrate with small subset the calculation and show the result for the sample data and how to get it (mathematically, not necessarily by code) folks will have better chance to write a solution.
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!