title: Function callback ('StopFcn' , 'TimerFcn' )for audiorecorder object in MATLAB?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/10520290/how-can-i-use-function-callback-stopfcn-timerfcn-for-audiorecorder-objec">How can I use function callback (&#39;StopFcn&#39; , &#39;TimerFcn&#39; )for audiorecorder object in MATLAB?</a>  </p>
  </blockquote>
  
  
  
  <p>So I try to this code.</p>
  
  <pre><code>% assume fs,winsize,winshift is given.
  
  T = 0.1; % in seconds
  samples = cell{100,1};
  r = audiorecorder(fs,16,1);
  k=1;
  r.TimerPeriod = 0.1;
  r.StopFcn = 'samples{k} = getaudiodata(r);';
  r.TimerFcn = {@get_pitch,samples{k},winsize,winshift};
  
  while 1
       record(r,T);
       k=k+1;
  end      
  </code></pre>
  
  <p>I want to execute the function 'get_pitch(samples,fs,winsize,winshift)' while during recording through audiorecorder object. </p>
  
  <p>But following exception occurs during execution.</p>
  
  <p>1) after record(r,T) is executed. (StopFcn is now called) ??? Error using ==> eval Undefined function or variable 'r'.</p>
  
  <p>2) after StopFcn is called (TimerFcn is now called) In this phase, get_pitch function have totally wrong parameters. For example, parameter in the position samples{k} change to 'audiorecorder object'.</p>
  
  <p>It seems that I do not know exact use of 'StopFcn' &amp; 'TimerFcn'.</p>
  
  <p>Is there anyone who can give me some advice? I really appreciate all of your comments.</p>