I would like to define enumerations and constants locally within the scope of a function.
I saw that MATLAB provides enumerations and constants as part of its object-oriented programming framework. However, if you try to define them within the scope of a function, they don't work. E.g. MATLAB complains with "Parse error: invalid syntax" if you try the following:
function output = my_function(input)
classdef my_constants
properties (Constant)
x = 0.2;
y = 0.4;
z = 0.5;
end
end
classdef colors
enumeration
blue, red
end
end
statements;
The reason seems to be that each classdef
needs to defined in its own.m
file.
I would like to avoid having an .m
file for every enumeration or set of constants that I use. Is there a way to do this? What are my options?
Addendum 1:
Sine I was asked for an example, here's one in pseudocode. This example depicts my need for defining and using local enumerations.
Say I have an enumeration type called colors
that can be RED
or BLUE
. I would like to define colors
locally in my function, and use it do control the flow of my statements in the function:
function output = my_function(input)
# ....
# Code that defines the enumeration 'colors'
#....
my_color = colors;
# ... code that changes 'my_color' ...
switch my_color
case RED
do this
case BLUE
do that;
end
Addendum 2:
Could I do this by leveraging Java code? If so, how?