How do I find the mean of certain parts of a cell array?

3 visualizaciones (últimos 30 días)
Michael Arvin
Michael Arvin el 24 de Feb. de 2022
Comentada: Jan el 24 de Feb. de 2022
Hello. I am trying to find the mean value of certain parts of a cell array. Each cell array row has 8192 values and I am trying to find the mean of each.
A snippet of the cell array:
For example the values of the first 2 rows of the cell array are:
I want to find the mean value of each column from a range of cell array rows 3-10.
Any ideas on how to do so?
Thank you very much!

Respuesta aceptada

Jan
Jan el 24 de Feb. de 2022
Editada: Jan el 24 de Feb. de 2022
This is easy, if you store the values in a numerical array instead of a cell. Why do you prefer a cell array?
But you can create the numerical matrix dynamically (although this is not really fast):
% mean value of each column from a range of cell array rows 3-10:
X = mean(cat(1, YourCell{3:10}), 1);
  4 comentarios
Jan
Jan el 24 de Feb. de 2022
You are welcome. Finding an efficient representation for the data is a crucial task in programming. Cell arrays are useful, if they contain elements of different sizes or classes. If all have the same size and class, a multi-dimensional array is (usually) better - except if it is huge and a set of smaller arrays would match into the RAM more likely.
Do I use an array of structs or a struct of arrays? Should I use the solution, which uses less memory or is faster to process? On one hand efficient code helps to save minutes of runtime, on the other hand a clean and clear code can avoid hours of debugging. Such questions belong to the work of an experiences programmer. And sometimes the best choice is not to decide for a specific representation, but to keep it flexible for later changes.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by