Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

matlab.lang.OnOffSwitchState class

Package: matlab.lang

Represent on and off states with logical values

Description

matlab.lang.OnOffSwitchState is an enumeration class that derives from the logical class. Use this class to implement properties that accept values of 'on' and 'off' and logical true, false, 1, or 0.

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

ClassLogical TrueLogical False

Character vector

'on'

'off'

String scalar

"on"

"off"

Logical

true

false

Logical and numeric

1

0

Enumeration member

matlab.lang.OnOffSwitchState.on

matlab.lang.OnOffSwitchState.off

Because OnOffSwitchState derives from the logical class, you can use these enumeration members in logical expressions.

Enumeration Members

offLogical false
onLogical true

Examples

expand all

Use OnOffSwitchState to define the class of these properties.

classdef SystemState
   properties
      Power matlab.lang.OnOffSwitchState = 'off'
      Monitor matlab.lang.OnOffSwitchState = 'off'
   end
   methods
      function val = isOn(obj)
         if ~(obj.Power && obj.Monitor)
            val = matlab.lang.OnOffSwitchState.off;
         else
            val = matlab.lang.OnOffSwitchState.on;
         end
      end
   end
end

Create an object and set the property values to 'on'.

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

You can call the isOn method to determine the state of the system. The method returns a logical value provided by the OnOffSwitchState enumeration.

if isOn(a)
   ...% System is ready to use
end

Introduced in R2017a

Was this topic helpful?