title: Force a Specific Camera Aquisition Framerate in a realtime Matlab Loop
body: <p>I have a function running in real time controlling hardware timing, etc. I want  to be able to record video as well, so I've created a global video object in matlab, and set the triggering to manual. Right now, I have it so that each iteration of the realtime loop I record a frame and write it to disk. I'm changing it so that Ill record to memory till I hit some limit, and then writing to disk. However, I'd like to guarantee no matter how fast the real time loop is running, I only capture 15 frames per second. </p>
  
  <p>Thinking about though, how can I make it so that I capture the 15 frames not so dramatically close to each other? If the real time loop is running lightning fast, the 15 frames will just be gathered at the "beginning" and capture almost no change that has occurred during that second. In other words, the faster real time loop is, the more my sampling will act like 1 frame per second (which has 14 other copies made). </p>
  
  <p>For example,</p>
  
  <pre><code>% Main File
  function start()
  
  global vid;
  global myLogger;
  vid = videoinput('winvideo', 1, 'MJPG_160x120');
  src = getselectedsource(vid);
  triggerconfig(vid, 'manual');
  vid.FramesPerTrigger = 1;
  vid.LoggingMode = 'disk&amp;memory';
  imaqmem(512000000); % 512 MB
  myLogger = VideoWriter('C:\Users\myname\Desktop\output.avi', 'Motion JPEG AVI');
  myLogger.Quality = 50;
  myLogger.FrameRate = 15;
  vid.DiskLogger = myLogger;
  src.FrameRate = '15.0000';
  vid.ReturnedColorspace = 'grayscale';
  
  start(vid);
  open(myLogger);
  
  initiateFastLoop();
  
  close(myLogger);
  
  stop(vid);
  
  
  end
  </code></pre>
  
  <p>The real time piece:</p>
  
  <pre><code>function initiateFastLoop
  
  
  global vid;
  global myLogger;
  
  while(flag)
      % perform lightning fast stuff
      frame = getsnapshot(vid);
      writeVideo(myLogger, frame);
  end
  
  end
  </code></pre>
  
  <p>The video generated is much higher framerate, and I don't want to capture a frame every single time realtime loop runs, and I don't want to set a simple upper limit because of the problem described above. Any help would be great!</p>