readEnum
FunctionThereadEnum
function in theshrlibsample
library displays a string that matches the input argument.
EXPORTED_FUNCTION char* readEnum(TEnum1 val) { static char outputs[][20] = { {"You chose en1"}, {"You chose en2"}, {"You chose en4"}, {"enum not defined"}, {"ERROR"} }; switch (val) { case en1: return outputs[0]; case en2: return outputs[1]; case en4: return outputs[2]; default : return outputs[3]; } return outputs[4]; }
The function signature is:
Return Type | Name | Arguments |
---|---|---|
cstring |
readEnum |
(Enum1) |
The values for theEnum1
input are defined in theshrlibsample.h
header file.
typedef enum Enum1 {en1 = 1, en2, en4 = 4} TEnum1;
This example shows how to pass enumeration values to thereadEnum
function in theshrlibsample
library. Load the library.
ifnot(libisloaded('shrlibsample')) addpath(fullfile(matlabroot,'extern','examples','shrlib')) loadlibrary('shrlibsample')end
In MATLAB, you can express an enumerated type as either the enumeration string or its equivalent numeric value. CallreadEnum
with a string argument.
calllib('shrlibsample','readEnum','en4')
ans = 'You chose en4'
CallreadEnum
with the equivalent numeric argument. TheEnum1
definition declares enumerationen4
equal to 4.
calllib('shrlibsample','readEnum',4)
ans = 'You chose en4'