MATLAB: Scalar vs nonscalar structure: advantages

MATLABstructures

Hi,
What are the advantages/disadvantages of both typs of structures?
I am about to save my research participant data in Matlab but undecided about which type of structure to use.
Thank you,
TD

Best Answer

What you want to do with your data? This documentation page gives two examples that show how each type of struct allows you to "slice" your data in a different way.
In the first example (the RGB image) accessing all the data in one color plane is easy while accessing all the data for a single pixel across the three planes is more involved.
In the second example (the patient data) accessing all the data for one patient is easy while accessing a particular piece of data for all patients is more involved.
I would like to point out one alternative that may be a better fit for your needs. If you have data arranged as a rectangular table consider storing it as a table array or a timetable array. If you look at the examples on the table documentation page you can see that you can access all data for a particular patient (in the "Specify Row Names" example) or all of a particular type of data for each patient ("Store Related Data Variables in Table") through one indexing expression.