how to create an enumeration class of strings ??
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Owen Zhang
am 6 Dez. 2018
Beantwortet: Brad Carman
am 12 Mär. 2020
Hi,
I'd like to create some enumeration classes to replace the hard-coded string values. But I met the problem occurs in the attached picture.
It's OK to derive from int , but fails to derive from char or string.
Anyone has some idea ? thank you in advance.
(I need the string values , to guarantee the code transition.)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198371/image.jpeg)
1 Kommentar
Akzeptierte Antwort
Weitere Antworten (1)
Brad Carman
am 12 Mär. 2020
It's also possible to so simply convert the enumeration name to a char
classdef SolverType
enumeration
NE_BACKWARD_EULER_ADVANCER
NE_PARTITIONING_ADVANCER
end
end
Then to get char:
char(SolverType.NE_BACKWARD_EULER_ADVANCER)
Which gives
ans =
'NE_BACKWARD_EULER_ADVANCER'
0 Kommentare
Siehe auch
Kategorien
Mehr zu String finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!