Advanced mean in cell arrays

조회 수: 4 (최근 30일)
federico nutarelli
federico nutarelli 2021년 3월 6일
편집: Jan 2021년 3월 7일
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
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by