Add Property Groups to System Object and Block Dialog

This example shows how to define property sections and section groups for System object™ display. The sections and section groups display as panels and tabs, respectively, in the MATLAB System block dialog.

Define Section of Properties

This example shows how to use matlab.system.display.Section and getPropertyGroupsImpl to define two property group sections by specifying their titles and property lists.

If you do not specify a property in getPropertyGroupsImpl, the block does not display that property.

 methods (Static, Access = protected)
    function groups = getPropertyGroupsImpl
       valueGroup = matlab.system.display.Section(...
            'Title','Value parameters',...
            'PropertyList',{'StartValue','EndValue'});
 
       thresholdGroup = matlab.system.display.Section(...
            'Title','Threshold parameters',...
            'PropertyList',{'Threshold','UseThreshold'});
       groups = [valueGroup,thresholdGroup];
    end
 end

Define Group of Sections

This example shows how to use matlab.system.display.SectionGroup, matlab.system.display.Section, and getPropertyGroupsImpl to define two tabs, each containing specific properties.

methods (Static, Access = protected)
   function groups = getPropertyGroupsImpl
      upperGroup = matlab.system.display.Section(...
           'Title', 'Upper threshold', ...
           'PropertyList',{'UpperThreshold'});
      lowerGroup = matlab.system.display.Section(...
           'Title','Lower threshold', ...
           'PropertyList',{'UseLowerThreshold','LowerThreshold'});
           
      thresholdGroup = matlab.system.display.SectionGroup(...
           'Title', 'Parameters', ...
           'Sections',  [upperGroup,lowerGroup]);
           
      valuesGroup = matlab.system.display.SectionGroup(...
           'Title', 'Initial conditions', ...
           'PropertyList',  {'StartValue'});
          
      groups = [thresholdGroup, valuesGroup];
   end
end

Complete Class Definition File with Property Group and Separate Tab

classdef EnhancedCounter < matlab.System 
   % EnhancedCounter  Count values considering thresholds
    
   properties
      UpperThreshold = 1;
      LowerThreshold = 0;
   end
   
   properties (Nontunable)
      StartValue = 0; 
   end
    
   properties(Logical,Nontunable)
      % Count values less than lower threshold
      UseLowerThreshold = true; 
   end
        
   properties (DiscreteState)
      Count;
   end
        
   methods (Static, Access = protected)
      function groups = getPropertyGroupsImpl
         upperGroup = matlab.system.display.Section(...
              'Title', 'Upper threshold', ...
              'PropertyList',{'UpperThreshold'});
         lowerGroup = matlab.system.display.Section(...
              'Title','Lower threshold', ...
              'PropertyList',{'UseLowerThreshold','LowerThreshold'});
           
         thresholdGroup = matlab.system.display.SectionGroup(...
              'Title', 'Parameters', ...
              'Sections',  [upperGroup,lowerGroup]);
           
         valuesGroup = matlab.system.display.SectionGroup(...
              'Title', 'Initial conditions', ...
              'PropertyList',  {'StartValue'});
           
         groups = [thresholdGroup, valuesGroup];
      end
   end
    
   methods (Access = protected)
      function setupImpl(obj)
         obj.Count = obj.StartValue;
      end
        
      function y = stepImpl(obj,u)
         if obj.UseLowerThreshold
            if (u > obj.UpperThreshold) || ...
                  (u <  obj.LowerThreshold)
               obj.Count = obj.Count + 1;
            end
         else
            if (u > obj.UpperThreshold)
               obj.Count = obj.Count + 1;
            end
         end
         y = obj.Count;
      end
      function resetImpl(obj)
         obj.Count = obj.StartValue;
      end
        
               
      function flag = isInactivePropertyImpl(obj, prop)
         flag = false;
         switch prop
            case 'LowerThreshold'
               flag = ~obj.UseLowerThreshold;
         end
      end
   end
end

See Also

| |

More About

Was this topic helpful?