Q&A
Ask and answer questions to make information more available to wider audiences.
Kaleb Ossitt @kalebossitt   18, Aug 2023 12:00 AM
Cell and Matrix in MATLAB
What is the difference between Cell and Matrix in MATLAB?
answers 3
 
Answer 1
Cesar Borne @bornecesar   30, Aug 2023 05:16 PM
The flip side of point 2 is that when you resize a matrix every element in the matrix must be copied over to the newly allocated memory area, but in the case of a cell array only a list of pointers needs to copied over. Depending on the size and type of elements you're storing, this might mean cell arrays are much faster to resize.
 
Answer 2
Cesar Borne @bornecesar   30, Aug 2023 05:16 PM
As far as memory layout goes, all elements of a matrix are laid out contiguously in memory, while a cell array contains pointers to each element of the array. This can be important when considering things like cache locality for high-performance code.
 
Answer 3
Cesar Borne @bornecesar   30, Aug 2023 05:16 PM
A cell array may contain any arbitrary type of an element in each cell; while a matrix requires the types of its elements to be homogeneous i.e. of the same type.