Advanced mean in cell arrays
1 回表示 (過去 30 日間)
古いコメントを表示
Hi aall,
this is a similar question to one I assked before. But it actualy diffes for a key detail so II opened a new issue.
so say I havve a cell array having 3 arrays each containing a 4x3 matrix (my original one has 150 matrices of size 11x75). The matrices have on the thid column an identifier of pprooducts and on the other two collumns sales values for a certain country (col name). Say I would like to do the mean of the sales for each product foorr each country so that I will avverage onlyh the values of products with the same identifier. So say I have a cell array containing matrices (where the bold elements are the identifiers):
cell1 = [1,2,3,9 ;4,8,7,4]
cell2 = [13,3,64,6;71,8,59,4]
cell3 = [31,43,54,9;41,18,17,1]
....
% Expected result:
[(71+4)/2,(8+8)/2,(59+7)/2,4;
(1+31)/2,(2+43)/2,(3+54)/2,9;
mean for prod 6 in each column ; mean for prod 1 in each column ...] where mean for prod 6 (or 1) in each column in this toy example iss the same as the values of each entry since they apppear only once.
Thank you,
Federico
1 件のコメント
Jan
2021 年 3 月 7 日
編集済み: Jan
2021 年 3 月 7 日
cell1 = [1,2,3,9 ;4,8,7,4]
This is not a cell, but a double matrix. Do you mean:
data = {[1,2,3,9 ; ...
4,8,7,4]; ...
[13,3,64,6; ...
71,8,59,4]; ...
[31,43,54,9; ...
41,18,17,1]}
"where the bold elements are the identifiers" - there are no bold elements.
Why do you store the data in three different arrays? And are they really cell arrays? If you joint the values to one matrix, the averaging is done by a call to accumarray.
"the thid column an identifier of pprooducts" - why do you calculate the average over the 3rd column then? Is this meaningful?
"the other two collumns sales values for a certain country (col name)" - What is a "col name"?
What happens with the rows containing the 4th element 1 and 6?
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!