Adding Arrays of cells
Show older comments
I have ten arrays of 15-dimensional A1, ..., A10 which consist of cells of different size. All arrays have same format i.e., same dimension of cells for all Ai, i=1,..10 respectively.
Ai = [2x1 double] [1x2 double] [2x2 double] [2x1 double] [2x2 double] [2x2 double] [2x2x2 double] [2x1 double] [2x2 double] [2x2 double] [2x2x2 double] [2x2 double] [2x2x2 double] [2x2x2 double] [4-D double]
I want A in same format where A is an array which have the mean of all components of cells of Ai, i =1,...,10. That is, A = (A1+ ... +A10)/10.
Please help me. Thanks :MSA
1 Comment
Stephen23
on 23 Sep 2017
"I have ten arrays of 15-dimensional A1, ..., A10..."
And that is the start of your problem right there. Do not create lots of numbered variables! Simply store your data in one array and your life will be much simpler (and your code faster and less buggy too).
This is what the MATLAB documentation says about your code idea: "A frequent use of the eval function is to create sets of variables such as A1, A2, ..., An, but this approach does not use the array processing power of MATLAB and is not recommended. The preferred method is to store related data in a single array."
You can read more explanations of the problems caused by accessing variable names dynamically:
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!