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

3 views (last 30 days)
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!

Accepted Answer

Jan
Jan on 24 Feb 2022
Edited: Jan on 24 Feb 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 Comments
Jan
Jan on 24 Feb 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!