title: How to access variables in the properties block of a Matlab System Object?
body: <p>I am working on a simple System Object in Matlab/Simulink.</p>
  
  <p>It looks like this :</p>
  
  <pre><code>classdef realtime_header_detectorSO &lt; matlab.System &amp; matlab.system.mixin.Propagates
      % correlateHeader
      %
      % This template includes the minimum set of functions required
      % to define a System object with discrete state.
  
      properties
         Header
         %nrOfBitsInPreviousStep=0;
         s=100;
         d=zeros(1,s);
  
  
  
      end
  
      properties (DiscreteState)
  
      end
  
      properties (Access = private)
                max_nr_of_packets=20;
        max_packet_length_in_bytes=300;
        current_packet=1;
          % Pre-computed constants.
       %   h = commsrc.pn('GenPoly', [9 5 0],'NumBitsOut', 8,'InitialStates',ones(1,9));
    %   data=logical(zeros(max_nr_of_packets,max_packet_length_in_bytes*8));
      end
  
      methods (Access = protected)
          function setupImpl(obj,u)
              % Implement tasks that need to be performed only once, 
              % such as pre-computed constants.
  
          end
  
          function [maxCorr]= stepImpl(obj,u)
              eml.extrinsic('num2str');
               coder.extrinsic('sprintf');
              % Implement algorithm. Calculate y as a function of
              % input u and discrete states.
              %y = size(u,1);
  
                  symbols=sign(u);
                  c=abs(conv(flipud(obj.Header),[symbols; symbols]));
  
                  maxCorr=max(c);    
                %  maxCorr
                  if(maxCorr==36)
  
                      idx36=find(c(1:size(symbols,1))==36);
                      disp('header(s) detected at the following location(s) in bytes:');
                      disp(sprintf('%15.4f \n',idx36/8));
                      nrOfSymbols=size(symbols,1);
                      disp(['out of nr. of total symbols: ' num2str(nrOfSymbols)]);
                      disp('------');
                  %    maxCorr
                  end
              % y=obj.pBufferIdx;
          end
  
          function resetImpl(obj)
              % Initialize discrete-state properties.
          end
  
          function varargout = isOutputFixedSizeImpl(~)
               varargout = {true};
          end
  
          function varargout = getOutputSizeImpl(obj)
             varargout = {[1 1]};
          end
      end
  
  end
  </code></pre>
  
  <p>However when I compile/run it I get the following error:</p>
  
  <pre><code>The System object name 'realtime_header_detectorSO' specified in MATLAB System block 'freqScanningRT/Sync and
  Find Header/detect header' is invalid.
  
  Caused by:
      Undefined function or variable 's'.
  </code></pre>
  
  <p><strong>However (!)</strong> the following code compiles and runs just fine :</p>
  
  <pre><code>classdef realtime_header_detectorSO &lt; matlab.System &amp; matlab.system.mixin.Propagates
      % correlateHeader
      %
      % This template includes the minimum set of functions required
      % to define a System object with discrete state.
  
      properties
         Header
         %nrOfBitsInPreviousStep=0;
         s=100;
    %     d=zeros(1,s);
  
  
  
      end
  
      properties (DiscreteState)
  
      end
  
      properties (Access = private)
                max_nr_of_packets=20;
        max_packet_length_in_bytes=300;
        current_packet=1;
          % Pre-computed constants.
       %   h = commsrc.pn('GenPoly', [9 5 0],'NumBitsOut', 8,'InitialStates',ones(1,9));
    %   data=logical(zeros(max_nr_of_packets,max_packet_length_in_bytes*8));
      end
  
      methods (Access = protected)
          function setupImpl(obj,u)
              % Implement tasks that need to be performed only once, 
              % such as pre-computed constants.
  
          end
  
          function [maxCorr]= stepImpl(obj,u)
              eml.extrinsic('num2str');
               coder.extrinsic('sprintf');
              % Implement algorithm. Calculate y as a function of
              % input u and discrete states.
              %y = size(u,1);
                  disp(obj.s);
                  symbols=sign(u);
                  c=abs(conv(flipud(obj.Header),[symbols; symbols]));
  
                  maxCorr=max(c);    
                %  maxCorr
                  if(maxCorr==36)
  
                      idx36=find(c(1:size(symbols,1))==36);
                      disp('header(s) detected at the following location(s) in bytes:');
                      disp(sprintf('%15.4f \n',idx36/8));
                      nrOfSymbols=size(symbols,1);
                      disp(['out of nr. of total symbols: ' num2str(nrOfSymbols)]);
                      disp('------');
                  %    maxCorr
                  end
              % y=obj.pBufferIdx;
          end
  
          function resetImpl(obj)
              % Initialize discrete-state properties.
          end
  
          function varargout = isOutputFixedSizeImpl(~)
               varargout = {true};
          end
  
          function varargout = getOutputSizeImpl(obj)
             varargout = {[1 1]};
          end
      end
  
  end
  </code></pre>
  
  <p>So I can access <code>s</code> in the <code>stepImpl(obj,u)</code> as <code>obj.s</code> but I cannot access <code>s</code> inside the properties block, where it is defined ! </p>
  
  <p>Now this is confusing. </p>
  
  <p>Is there way to access <code>s</code> inside the properties block ?</p>
  
  <p>The problem is that I have to use the properties block because if I try this :</p>
  
  <pre><code> function setupImpl(obj,u)
          % Implement tasks that need to be performed only once, 
          % such as pre-computed constants.
          d=zeros(1,obj.s);
  
    end
  </code></pre>
  
  <p>then I get :</p>
  
  <pre><code>Error due to multiple causes.
  
  Caused by:
      Problem creating simulation target MEX-file for model 'freqScanningRT'.
      Simulink detected an  error
       'Computed maximum size is not bounded.
      Static memory allocation requires all sizes to be bounded.
      The computed size is [1 x :?].'.
  
       The error occurred for MATLAB System block 'freqScanningRT/Sync and Find Header/detect header'. See line
       34, column 15 in file
       'path/realtime_header_detectorSO.m'.
       The error was detected during code generation phase.
       Start code generation report.
  
       To prevent this error, use one of the following:
       * Modify the System object to avoid code that does not support code generation.
       * Change 'Simulate using' parameter to 'Interpreted Execution'.
  </code></pre>
  
  <p>Any idea how to refer to variables in the <code>properties</code> blocks ?</p>
  
  <p>There must be a way to do this.</p>