注册 | 登录

解决user interface - How to use impoly with msgbox in matlab gui?

itPublisher 分享于



Requirement : I am creating a matlab gui project. I have a pushbutton in my code, when clicked creates a figure displaying an image from the parent GUI with a msgbox as a popup. After clicking ok on the msgbox I want to select the region of interest using impoly command.

Problem: Now the problem is after clicking the ok button on the msgbox the impoly command doesn't work. The mouse pointer doesn't change into a selector. I have searched the matlab documentation and the alternate is warndlg but the same happens.

Here is my code :

% --- Executes on button press in roi.
function roi_Callback(hObject, eventdata, handles)
% hObject    handle to roi (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
image=getimage(handles.axes2);    % acquire image from parent gui
figure;                           % figure;
msgbox('Select ROI for overlapped area','overlapped region');   %message box
im=imshow(image);      % to show the image in figure;
data12=impoly;         % creates a roi polygon selector
mask12=createMask(data12,im); % creates a binary mask
matlab user-interface image-processing matlab-figure matlab-guide
  this question
asked Jan 30 '16 at 15:20 sakyan 15 5


1 Answers


You have to call the msgbox within the uiwait function.

This allows blocking the execution of the callbak until the user press the OK button.

% msgbox('Select ROI for overlapped area','overlapped region'));   %message box
uiwait(msgbox('Select ROI for overlapped area','overlapped region'));   %message box

Hope this helps. Qapla'

  this answer
answered Jan 30 '16 at 15:45 il_raffa 3,131 8 15 31      Thanks a lot, It's working now. –  sakyan Jan 30 '16 at 16:13      You're welcome! In order to close the question youi might want to mark the answer as 解决方法. –  il_raffa Jan 30 '16 at 16:46









您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱