cell array or multidimensional array?
Show older comments
Which of the two is more MATLAB-friendly?
- Cell Array, or
- Multidimensional Array
If cell arrays are better than multidimensional arrays, how should I define the following array in cell array format:
A(128, 128, 17, 4, 25)
Suppose A is:
A(X, Y, Z, VARS, TIMES)
which means A contains the value of some variables VAR1, VAR2, ..., VARN in a 3D space in different times.
Accepted Answer
More Answers (2)
Andy
on 19 May 2011
4 votes
Obviously it depends: is all of your data numeric, or are the data types mixed? If the data is all numeric, then I'd say stick with a numeric array. If it's mixed, use a cell array.
EDIT (more explanation): There are lots of functions designed to manipulate numeric data stored in an array (all of the operators, mathematical functions, etc.). If you store your data in a cell array, you need to convert back to a numeric array every time you need to calculate, say, the mean of your data. I cannot think of any functions that operate on cell arrays of numeric data that don't also operate on numeric arrays of numeric data. Also, cell arrays introduce lots of opportunity for hard to find typos (like typing myCell(1) instead of myCell{1}).
You should use cell arrays only when you really have to. That is when you have data of mixed type or arrays of different sizes. Otherwise, stick with numeric arrays.
1 Comment
Sean de Wolski
on 19 May 2011
+1
Oleg Komarov
on 19 May 2011
1 vote
Cell arrays have significant overhead and they are slower wrt do a double nD array but they can mix datatypes.
Categories
Find more on Data Type Identification 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!