I'm making a GUI with guide. I have a push button the user clicks and the callback is as folows : (what matters are the tirst two lines really...

```
   function SetParticleRoiSize_Callback(hObject, eventdata, handles)
% hObject    handle to SetParticleRoiSize (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles=guidata(hObject);
particleroiSize=imrect;% - draw a rectagle around the particle to get a meausr eof ROI size
roiPoints=getPosition(particleroiSize); %-get tha parameters fo the rectanlge
partX1 = round(roiPoints(1));
partY1 = round(roiPoints(2));
partX2 = round(partX1 + roiPoints(3));
partY2 = round(partY1 + roiPoints(4)); % these are the ROi positions in pixels

roiHeight = round(roiPoints(3)); % - these are just the ROI width and height
roiWidth  = round(roiPoints(4));

handles=guidata(hObject); %_ update all the handles...
handles.partX1=partX1;
handles.partX2=partX2;
handles.partY1=partY1;
handles.partY2=partY2;

handles.roicenterX = (partX1 + round(roiPoints(3))/2);
handles.roicenterY= (partY1 + round(roiPoints(4))/2);

handles.roiHeight = roiHeight;
handles.roiWidth = roiWidth;

current_slice = round(get(handles.Image_Slider,'Value'));
handles.current_slice=current_slice;
particleImage=handles.Image_Sequence_Data(partY1:partY2,partX1:partX2,current_slice);
handles.particleImage=particleImage;

set(handles.RoiSizeDisplay,'String',['Particle ROI is ',' ',num2str(roiHeight),' ', ' by ',num2str(roiWidth)] );

guidata(hObject,handles);  %- at this point we now have the particle in the roi and the size of the roi stored.

```

The issue I am having is that when the user clicks the button the first time, nothing happens (i.e. the imrect line seems to not get called at all). When the user clicks the button again then they can draw a rectangle on the image but my program throws out an error 

```
Error in imrect (line 83)
            [h_group,draw_api] = imrectAPI(varargin{:});

Error in SemiAutomated_Fionv2p2_5>SetParticleRoiSize_Callback (line 291)
particleroiSize=imrect;% - draw a rectagle around the particle to get a meausr eof ROI size

Error in gui_mainfcn (line 96)
        feval(varargin{:});

Error in SemiAutomated_Fionv2p2_5 (line 56)
    gui_mainfcn(gui_State, varargin{:});

Error in
@(hObject,eventdata)SemiAutomated_Fionv2p2_5('SetParticleRoiSize_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback

```

I guess the error is because there is no imrect created on the first button click. 
Can someone please explain to me why this button needs to be clicked twice to work? (and even then it still gives an error...)

thanks...
-j