Getting the mean from each cell row in a cell array
Show older comments
I have a cell array called data. This is the first row.
A = {5×1 double}, B = {4×1 double}, C = {7×1 double}
I want to get the mean of each row from all cells. For example, if we cell2mat each cell we get
A = 1 B = 2 C = 3
2 4 6
3 6 9
4 8 1
5 5
6
8
I want this output, D:
D = (1 + 2 + 3)/3 = 2
(2 + 4 + 6)/3 = 4
(3 + 6 + 9)/3 = 6
(4 + 8 + 1)/3 = 4.3
(5 + 5)/2 = 5
6
8
I tried converting the cells into matrices and then combining them.
[rw,cs] = size(data);
matrix = [];
for x = 1:rw
for y = 1:cs
matrix = cell2mat(data(x, y));
matrix(n) = data;
end
end
This returns an error that: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Accepted Answer
More Answers (0)
Categories
Find more on Resizing and Reshaping Matrices 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!