主要内容

matlab.lang.OnOffSwitchState class

Package:matlab.lang

Represent on and off states with logical values

Description

matlab.lang.OnOffSwitchState是从logicalclass. Use this class to specify the data type of properties that accept values of'on''off'和逻辑真的,false,1, or0.

Use this class to constrain property values to any of these values:

Class Logical True Logical False

Character vector

'on'

'off'

String scalar

"on"

“离开”

Logical

真的

false

Logical and numeric

1

0

Enumeration member

matlab.lang.OnOffSwitchState.on

matlab.lang.OnOffSwitchState.off

BecauseOnOffSwitchState来源于logicalclass, you can use these enumeration members in logical expressions.

枚举成员

off Logical false
Logical true

Examples

collapse all

Create a class to represent the state of a computer whose power and monitor can be turned on and off separately. UseOnOffSwitchStateto define the class of these properties.

classdefSystemState特性Powermatlab.lang.OnOffSwitchState='off'监视器matlab.lang.OnOffSwitchState='off'endmethodsfunctionval = isOn(obj)if〜(obj..power && obj.monitor)val = matlab.lang.onoffswitchstate.off;elseval = matlab.lang.OnOffSwitchState.on;endendendend

Create aSystemStateobject and set the property values to'on'.

a = SystemState; a.Power ='on'; a.Monitor ='on';

Call theisOn方法确定的状态the system. The method returns a logical value provided by theOnOffSwitchStateenumeration.

ifison(a)...% System is ready to useend

More About

expand all

Version History

Introduced in R2017a