exponenta event banner

Определение информации о системных объектах

В этом примере показано, как определить информацию для отображения для системного object™.

Определение информации о системных объектах

Вы можете определить свой собственный info для отображения определенной информации о системном объекте. Дефолт infoImpl возвращает пустую структуру. Это infoImpl метод возвращает подробную информацию, когда info вызывается с помощью info(x,'details') или только информацию подсчета, если она вызвана с помощью info(x).

methods (Access = protected)
   function s = infoImpl(obj,varargin)
      if nargin>1 && strcmp('details',varargin(1))
         s = struct('Name','Counter',
             'Properties', struct('CurrentCount',obj.Count, ...
             'Threshold',obj.Threshold));
      else
         s = struct('Count',obj.Count);
      end
   end
end

Завершить файл определения класса с помощью InfoImpl

classdef Counter < matlab.System
   % Counter Count values above a threshold
   
   properties
      Threshold = 1
   end
   
   properties (DiscreteState)
      Count
   end
   
   methods (Access = protected)
      function setupImpl(obj)
         obj.Count = 0;
      end
       
      function resetImpl(obj)
         obj.Count = 0;
      end
       
      function y = stepImpl(obj,u)
         if (u > obj.Threshold)
            obj.Count = obj.Count + 1;
         end
         y = obj.Count;
      end
     
      function s = infoImpl(obj,varargin)
         if nargin>1 && strcmp('details',varargin(1))
            s = struct('Name','Counter',...
            'Properties', struct('CurrentCount', ...
            obj.Count,'Threshold',obj.Threshold));
         else
            s = struct('Count',obj.Count);
         end
      end
   end
end

См. также