I know that a structure can be defined by in several ways such as:
-
Adding fields to a variable
p.color.red = .2; p.color.green = .4; p.color.blue = .7; -
Defining a scalar structure by assignment
S = struct('a', 0, 'b', 1, 'c', 2);
What I want to be able to do is create a structure definition (like C). My end goal is to have an array of structures that i can iterate through and perform testing on. Is there any way I can define a generic structure and then create instances of it? Should I use some other mechanism. I know MATLAB supports Java, should I use a class/interface?
Unlike C, Matlab allows you to add or remove members from a struct as you go. It’s more of a convention that a struct with certain fields can be used with certain functions.
So yes, those are the two basic ways to create structures. Of course, you can always write a function in a *.m file which creates a structure with certain fields for you. Or if you want to get more OO, see here