scalar vs nonscalar structure: advantages?
Show older comments
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
1 Comment
I've never found a situation in which I'd need to choose between the two, to be honest. Putting aside the fact that I hate structures and use classes instead, since one is scalar and one is non-scalar that means, by definition, they are suitable for different scenarios. So even though it is obvious the only real advantage and disadvantage of the two is their property of being scalar or non-scalar and in most situations your data dictates whether you need something scalar or not! Both are still structures - basically like a christmas tree that you can just hang anything on and don't know what it is until you interrogate the struct.
Accepted Answer
More Answers (1)
Jakob B. Nielsen
on 10 Mar 2020
There are probably people out there much smarter than me, so take this with a grain of salt.
If it were me, I would choose that my "main structure" should be a scalar structure - e.g. one simply called data. Inside this structure, you can then have multiple fields which can be other structures if you want, and each of these structures can be scalar or nonscalar as you choose. (You can also have cells, arrays, both of character and double, within all of these substructures). The primary advantage here is that a simple
save('researchdata.mat','data');
Saves all your stuff. As well as that your workspace is not cluttered, since it only has the one variable.
Categories
Find more on Tables in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!