Q&A
Ask and answer questions to make information more available to wider audiences.
Caroline Laeton @laetoncaroline   22, Aug 2023 12:00 AM
constants properties in a class
How to define constants properties in a Class?
answers 1
 
Answer 1
Drake Boot @bootdrake85   31, Aug 2023 11:22 AM
To create Constants properties you should declare the Constant attribute in the property blocks. Setting the Constant attribute means that, once initialized to the value specified in the property block, the value cannot be changed. For example, let's create a class to perform degree to radian conversion:
classdef NamedConst
   properties (Constant)
      R = pi/180
      D = 1/NamedConst.R
   end
end

To referencing the constant properties, refer to the constant using the class name and the property name, i.e. ClassName.PropName. For example,
>> radi = 45*NamedConst.R
radi =

    0.7854