title: Matlab Gui For Webcam Capture and Screenshot
body: <p>I am trying to make a GUI in Matlab with 2 views and 2 buttons.
  In first view I want to show a video captured from webcam in real time and in second view I want to display a screenshot of video from first view when I press the "Capture image" button. </p>
  
  <p>The problem is that when I press the "Capture image" button, the video and the screenshot switches their positions. I want the screenshot in the second view. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>    % --- Executes on button press in startStopCamera.
  function startStopCamera_Callback(~, ~, handles)
  % hObject handle to startStopCamera (see GCBO)
  % eventdata reserved - to be defined in a future version of MATLAB
  % handles structure with handles and user data (see GUIDATA)
  
  % Start/Stop Camera
  if strcmp(get(handles.startStopCamera,'String'),'Start Camera')
      % Camera is off. Change button string and start camera.
      set(handles.startStopCamera,'String','Stop Camera')
      axesHandle= findobj(gcf,'Tag','VideoCapture');
      preview(axesHandle, handles.video);
  
      start(handles.video)
      set(handles.captureImage,'Enable','on');
      % Update handles structure
  guidata(hObject, handles);
  else
      % Camera is on. Stop camera and change button string.
      set(handles.startStopCamera,'String','Start Camera')
     % axes(handles.VideoCapture);
      stop(handles.video)
      set(handles.captureImage,'Enable','off');
  end
  
  end
  % --- Executes on button press in captureImage.
  function captureImage_Callback(~, ~, handles)
  % hObject    handle to captureImage (see GCBO)
  % eventdata  reserved - to be defined in a future version of MATLAB
  % handles    structure with handles and user data (see GUIDATA)
  axesHandle= findobj(gcf,'Tag','Screenshot');
  frame = getsnapshot(handles.video);
  %frame = get(get(handles.Screenshot,'children'),'cdata'); % The current displayed frame
  
  preview(axesHandle, frame);
  
  end
  </code></pre>