title: Get Errors when running Simulink block, but get Success when running respective M-file alone
body: <p>I would like to transmit an encoded image using USRP. The first step is to load the image using Matlab and encode it. The respective codes are shown as follows.</p>
  
  <pre><code>function msg = genMsg1
  %#codegen
  persistent msgStrSet count;
  if isempty(msgStrSet)
    count = 0;
    msgStrSet = imread('cameraman.tif'); % Load the image of cameraman.tif
  end
  msgtemp = dec2bin(msgStrSet); % Covert msgStrSet into binary value
  msg_1ine = msgtemp(count+1,:).'; % Take msgtemp line by line and tranpose it
  msg = str2num(msg_1ine);  % Convert each line from string into column vector
  count = mod(count+1,65536);
  end
  </code></pre>
  
  <p>And the running result of this M-file is:
  ans =</p>
  
  <pre><code> 1
   0
   1
   0
   0
   0
   0
   0
  </code></pre>
  
  <p>Since I should use the block of SDRU transmitter, I have to encode above codes into a matlab function, which is shows as following figure. 
  <img src="https://i.stack.imgur.com/wYTv0.jpg" alt="enter image description here"></p>
  
  <p>But when I run this block, error windows pops up, as the following figure shows.</p>
  
  <p><img src="https://i.stack.imgur.com/bXDZS.jpg" alt="enter image description here"></p>
  
  <p>The first error is:</p>
  
  <pre><code>Subscripting into an mxArray is not supported.
  Function 'MATLAB Function' (#46.311.329), line 11, column 12:
  "msgtemp(count+1,:)"
  Launch diagnostic report.
  </code></pre>
  
  <p>The second error is</p>
  
  <pre><code>Undefined function or variable 'msg_1ine'. The first assignment to a local variable determines its class.
  Function 'MATLAB Function' (#46.391.399), line 12, column 15:
  "msg_1ine"
  Launch diagnostic report.
  </code></pre>
  
  <p>The third error and fourth error are the same.</p>
  
  <pre><code>Errors occurred during parsing of MATLAB function 'MATLAB Function'(#45) 
  </code></pre>
  
  <p>I think the second, third and fourth errors are due to the first error, </p>
  
  <pre><code>Subscripting into an mxArray is not supported.
  </code></pre>
  
  <p>I have search the internet for the whole day, and still could not find the similar problem. Could anyone tell me what is "Subscripting into an mxArray is not supported" after all and how to solve it?</p>
  
  <p>Thanks in advance for any leading!</p>