Performance comparison among Struct Array, Cell Array and Table
267 views (last 30 days)
I am facing an issue when to use what. There are three common way to store data in MATLAB: 1. Cell array; 2. Tables; 3. Struct arrays.
I did some search online for the performance among three of them: Struct will be the fastest, but still not really clear when to use what.
Can someone give me a general concept of the performance among these MATLAB data structures?
Matt J on 1 Nov 2018
Edited: Matt J on 1 Nov 2018
They should all be about the same speed. If speed matters and the data is large, however, you shouldn't be using any of these. You should be storing data in numeric arrays instead. That way the data will be held contiguously in RAM and accessing it will be very fast.
Bruno Luong on 2 Nov 2018
My general rule of thumbs:
- Simple Array is the fastest
- Using cell if you don't have a choice (mixing class or uniform sizes) and don't care about how to "name" elements.
- Next recommendation is using struct of arrays and/or cell-arrays, that allows to have meaningful fieldnames, and flexible data exchanges.
- Avoid at all cost array of structs for large number of records (said > 10), this will soon or later have big penalty of speed. I can't remember the last tile I use it, probably in my youth and never did it again.
- Table is sort of Object Oriented built on top of CELL, personally I never feel a need to use it. I recognize it's very attractive for people who like excel sheet. ;-)
Peter Perkins on 6 Nov 2018
Kat, there's no way you are gonna get a useful answer without providing more information. The best representation of your data is gonna depend on your data and what you are doing, and how you plan on writing your code. Without knowing that, any answer is just guessing.