I asked the same question over on StackOverflow, and after a lot of trial and error, managed to answer my own question, although maybe one of you have a better solution than I. I will reiterate the solution with images here, since I can't post them over there:
Firstly, my example above produced errors because my Example enum was based on a uint32. I was unaware that uint32 was not a valid enumeration type. Changing it to a uint16 eradicated the Simulink error message but did not produce the desired or expected behavior.
classdef Example < uint16
enumeration
value1 (1)
value2 (2)
value13 (13)
value999 (999)
end
methods
function ind = subsindex(e)
if(isa(e, 'Example'))
ind = find(enumeration('Example') == e, 1) - 1;
else
ind = 0;
end
end
end
end
With my class defined in Example.m, this is the behavior I get in MATLAB:
>> A = uint16(zeros(1, length(enumeration('Example'))))
A =
1×4 uint16 row vector
0 0 0 0
>> A(Example.value13) = 1
A =
1×4 uint16 row vector
0 0 1 0
Perfect. Beautiful. Precisely what I want. Now let's try it in Simulink.
So despite using the same enumeration defined externally in Example.m with the same subsindex, what I would define as the same coding setup (using the enumeraton as an index) produces different results. Instead of the custom subsindex being invoked, Simulink automatically casts the enumeration to its integer equivalent, generating the Simulink equivalent of an "Index out of bounds" exception.
The solution I settled upon involved using a Simulink Function to call a MATLAB function that searches for the correct index using the "find" command. In my particular instance, I was assigning the data to Data Store Memory, so I was able to just pass the enumeration index and a new value to these blocks, but you could just as easily have a single enumeration input block that spits out the requested index as a uint16.
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function SetAVal(ExampleEnum, NewValue)
global A;
if(isa(ExampleEnum, 'Example'))
A(find(enumeration('Example') == ExampleEnum, 1)) = NewValue;
end
The logic would get more complicated if you wished to use vectors and write multiple values at once, or, as previously stated, wished to assign to any generalized vector, but this is at least a starting point. It should just be a matter of modifying the Simulink and MATLAB functions to allow vector inputs and looping through those inputs in the MATLAB function.