matlab gui循环,user-interface – 在MATLAB GUI中断开for循环

您遇到的问题是传递给句柄的

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值