Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
Michael Arvin
Michael Arvin am 24 Feb. 2022
Kommentiert: Jan am 24 Feb. 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!

Akzeptierte Antwort

Jan
Jan am 24 Feb. 2022
Bearbeitet: Jan am 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 Kommentare
Jan
Jan am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by