finding mean for an array
5 次查看(过去 30 天)
显示 更早的评论
Hi all, Just wanted to find mean for an array thnx
0 个评论
采纳的回答
Walter Roberson
2011-3-3
For numeric arrays:
mean(NumericArrayName(:))
I see, though, that you tagged this with "cell arrays". If you are wanting to find the mean for each cell separately, then:
cellfun(@(C) mean(C(:)), CellArrayName)
If you are wanting to find the mean of all of the cells taken together as if they were one long list of numbers:
t = cellfun(@(C) C(:), CellArrayName);
mean(vertcat(t{:}))
I am presuming in the above that when you say that you want to find the mean for an array, that you want the mean of all of the numbers in the array together. If you want the mean of the rows of an arithmetic array, then mean(NumericArrayName,2) and if you want the mean of the columns then mean(NumericArrayName)
But if what you have is a cell array containing a series of numeric arrays all the same size, and you want a position-by-position mean over all of the cells, then:
nd = ndims(CellArrayName{1});
mean(cat(nd, CellArrayName{:}), nd)
2 个评论
Walter Roberson
2011-3-3
Your code to find the mean of each group appears to be okay.
What do you want to plot against?
plot(cellfun(@mean, cel))
perhaps?
By the way:
a=[164 165 166 167 175 176 177 189 190 195 196]';
b=diff(a); %find differences
idx = find([b 2]>1); %find there indexes
cel = mat2cell(a, 1, [idx(1) diff(idx)]); %break up the matrix
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!