필터 지우기
필터 지우기

"successor" and "predecessor" functions for enumerated types

조회 수: 2 (최근 30일)
Jim Johnson
Jim Johnson 2012년 1월 19일
When working with enumerated types it is sometimes necessary to access the preceding enumerated value or the next enumerated value. There are no built-in methods for this so has anybody come up with user built methods? An example is the StateMate function enum_succ(in_value) that returns the enumerated value which is the successor to the in_value enumerated value
  댓글 수: 3
Jim Johnson
Jim Johnson 2012년 1월 19일
Yes indirectly about StateFlow, but specifically about embedded matlab functions EML in a StateFlow diagram. So if I can get a function that works in Matlab, chances are I can make the EML function work.
Walter Roberson
Walter Roberson 2012년 1월 19일
MATLAB itself does not offer any enumerated types (but such things could be defined by way of an OOP class, I suppose.)

댓글을 달려면 로그인하십시오.

답변 (2개)

Andrew Newell
Andrew Newell 2012년 1월 19일
You could make a linked list with an enumerated class as one of its properties. See Example — Implementing Linked Lists and How to Define Enumerated Data in a Stateflow Chart.

Walter Roberson
Walter Roberson 2012년 1월 19일
It appears to me that you could add your own methods to the enumeration; you are defining a class and there is not obvious barrier against it. See http://www.mathworks.com/help/toolbox/simulink/ug/brscgt1-1.html#brsebyf-1
The enumerations are described as not needing to be consecutive or even ordered, so there is no inherent succ() or pred() ordering (e.g., next higher or next lower integer value.) Might drive you to a switch statement that listed each case. Or if you could store a private array, list the values in order in a private array, then when called, find() the current value in the list and extract the next or previous as appropriate.

카테고리

Help CenterFile Exchange에서 Complex Logic에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by