Get the avarage for coresponding cell contents from a cell array
Mostrar comentarios más antiguos
Hi,
I have two cell arrays.
- data = 1x175 cell (rows double array is not consistent for each cell. There are some cells which do not even have values.)
- Z1cell = 1x278 cell (each cell has a double array of 5479 rows)
I need to go through each cell of "data" and get the values for each cell, for example, data{1,1} has 272, 273,274. Then I need to get the corresponding cell from Z1cell, in this case, cell 272,273 and 274, and get the average for each row.
Hope I explained clearly.
Please see the two .mat files (data and Z1ccell) are attached.
Sample code I was trying is as follows but not working. Perhaps there may be an efficient way.
for k=1:175
[m]=data{1,k}
ave(:,k)=mean(Z1cell{1,m});
end
Thanks for the help in advance.
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 24 de Oct. de 2014
0 votos
Because m could have a variable number of rows, that means the mean will have that same variable number of rows and "ave" will have that same variable number of columns. That means ave should be a cell array. You can make ave a double, but it must be at least as wide as the largest length you ever expect m to be and you must pre-allocate it, and then you need to adjust the second index of ave so that it's not k but 1:length(m), and you will have some empty aves that just remain zero. Having it be a cell array is probably simpler.
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!