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

2 次查看(过去 30 天)
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!

采纳的回答

Jan
Jan 2022-2-24
编辑:Jan 2022-2-24
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 个评论
Jan
Jan 2022-2-24
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by