您遇到的问题是传递给句柄的
opening function的值的结构是固定在调用打开函数时的值.您永远不会检索由pushbutton_Callback更新的新结构.您可以通过在循环中调用
GUIDATA来检索新结构.以下是我建议您尝试编写循环的方法:
handles.stop_now = 0; %# Create stop_now in the handles structure
guidata(hObject,handles); %# Update the GUI data
while ~(handles.stop_now)
drawnow; %# Give the button callback a chance to interrupt the opening function
handles = guidata(hObject); %# Get the newest GUI data
end
更大的GUI设计问题……
根据评论中有关您要使用GUI完成的内容的其他说明,我认为可能有更好的方法来设计它.用户不必连续循环以重复输入ROI,然后按下按钮停止,您可以取消循环和停止按钮,并在GUI中添加“添加ROI”按钮.这样,用户只需按下按钮即可添加其他ROI.您可以先使用以下初始化替换open函数中的for循环:
handles.nROIs = 0; %# Current number of ROIs
handles.H = {}; %# ROI handles
handles.P = {}; %# ROI masks
guidata(hObject,handles); %# Update the GUI data
然后,您可以使用以下内容替换按钮的回调:
function pushbutton_Callback(hObject,eventdata,handles)
%# Callback for "Add new ROI" button
nROIs = handles.nROIs+1; %# Increment the number of ROIs
hROI = imfreehand; %# Add a new free-hand ROI
position = wait(hROI); %# Wait until the user is done with the ROI
handles.nROIs = nROIs; %# Update the number of ROIs
handles.H{nROIs} = hROI; %# Save the ROI handle
handles.P{nROIs} = hROI.createMask; %# Save the ROI mask
guidata(hObject,handles); %# Update the GUI data
end