Q&A
Ask and answer questions to make information more available to wider audiences.
Harrison Birney @birneyharrison   22, Aug 2023 12:00 AM
Cell array vs. a Struc
When is it appropriate to use a Cell array vs. a Struct in Matlab?
answers 2
 
Answer 1
Chance Boorman @boormanchance   31, Aug 2023 10:40 AM
It is better to use Structs when:
You need to store data (and return an output), since the field names are (should be) self-documenting, so you don't need to remember what information you had in column 7 of a cell array. Also, you can easily include a field 'help' in your structure where you can put some additional explanation of the fields, if necessary.

You want to update your code at a later date, replace them with objects without needing to change your code (at least in case you did pre-assignment of your structure). They have the same syntax, but objects will allow you to add more functionality, such as dependent properties (i.e. properties that are calculated on the fly based on other properties).

In the end, it's also a matter of convenience and code clarity. If you prefer to refer your variable elements by number(s) or by name. Then use cell array in the former case and struct array in later.
 
Answer 2
Chance Boorman @boormanchance   31, Aug 2023 10:39 AM
It is better to use Cell Arrays when:
You need to store data for computation within a function, since they're more convenient to handle, thanks to e.g. to CELLFUN function.