title: Matlab videoinput: Matlab has encountered an internal error and needs to close
body: <p>I am trying to run a program that opens a webcam, takes a screenshot, processes it, and shows the output. My code runs correctly and I am getting output, but when I close the output window I get this error every-time:</p>
  
  <blockquote>
    <p>Matlab System Error: Matlab has encountered an internal problem and needs to close.</p>
  </blockquote>
  
  <p>As I am new to Matlab can anyone help me? I am using Windows 8 operating system and Matlab R2013a.</p>
  
  <p>This is the code:</p>
  
  <pre><code>    clear all;
      close all;
      clc;
      video=videoinput('winvideo',1);
      preview(video);
      while(true)
      data=getsnapshot(video);
      R=data(:,:,1);
      G=data(:,:,2);
      B=data(:,:,3);
      for i=1:768
          for j=1:1024
             if(R(i,j)&lt;128)
                 out(i,j)=1;
             else
                 out(i,j)=0;
             end
         end
     end
     cla; % Prevent stuffing too many images into the axes.
     imshow(out);
     drawnow;
     end
  </code></pre>