Getting the mean from each cell row in a cell array
이전 댓글 표시
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.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!