MATLAB Answers

convert an enum to another type of enum

James Marriott 님이 질문을 제출함. 12 Sep 2018
최근 활동 TAB 님이 답변함. 17 Sep 2018
I have an enum of for example 'Gender' (Male =0 , Female =1) and I have another enum own 'MyGender' enum (Male =0 , Female =1, Unknown =2)
My question is how can I write something quick and nice to convert from their enum to mine?
In Matlab it is possible to do this:
Var1 = Gender.Male
Var2 = MyGender.(char(Var1))
But when I do this is a state machine is simulink I get the following error:
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are
inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:Stateflow | Category:Coder error
Non-constant expression or empty matrix. This expression must be constant because its value determines the size or
class of some expression.
Can someone suggest a better implementation that will work with code gen also.
Thanks

  댓글 수: 0

로그인 to comment.

답변 수: 1

TAB 님의 답변 17 Sep 2018
 채택된 답변

If your enums definitions are compatible, then you can convert them directly in Simulink using "Data Type Conversion" block.
Another option, convert the first enum value to integer and then convert integer to second enum type.

  댓글 수: 0

로그인 to comment.



Translated by