Are there enumerated types in MATLAB? If not, what are the alternatives?
相关问题
- Extract matrix elements using a vector of column i
- What is the fastest for Map keys: Enum.valueOf(~)
- How do you get R's null and residual deviance
- Switch String with Enum variables
- How to display an image represented by three matri
相关文章
- Enum with associated value conforming to CaseItera
- Why do I have to cast enums to int in C#?
- How do I append metadata to an image in Matlab?
- Why doesn't reflections.getSubTypesOf(Object.c
- How can I get enum possible values in a MySQL data
- How can I write-protect the Matlab language?
- Bind a char to an enum type
- ClassLoad an Enum type
If you need the enumerated types just for passing to C# or .NET assembly, you can construct and pass the enums with MATLAB 2010:
you can also check the official MathWorks answer at
You could make a Matlab class that behaves like a Java's old typesafe enum pattern. A modification of Marc's solution could take it from C-style typedefs to more like Java-style typesafe enums. In this version, the values in the constants are typed Color objects.
The upsides:
Downsides:
On the whole, I don't know which approach is better. Haven't used either in practice.
Here's a function to exercise it.
Example of use:
A minor quirk in both approaches: the C convention of putting the constant on the left hand of the "==" to prevent bad assignment doesn't help as much here. In Matlab, if you accidentally use "=" with this constant on the LHS, instead of an error, it'll just create a new local struct variable named Colors, and it will mask the enum class.
There is actually a keyword in MATLAB R2009b called 'enumeration'. It seems to be undocumented, and I cannot say I know how to use it, but the functionality is probably there.
You can find it in
matlabroot\toolbox\distcomp\examples\+examples