使用回调时更新GUI句柄

Niseonna

我有一个由GUIDE制成的GUI,当我在回调中调用回调时,我不知道如何更新GUI句柄。因此,例如在调用该函数的函数中,我所拥有的是:

function start_ss_Callback(hObject, eventdata, handles)
% hObject    handle to start_ss (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of start_ss as text
%        str2double(get(hObject,'String')) returns contents of start_ss as a double
start_hh_Callback(hObject, eventdata, handles)

并且start_hh_Callback我有下面给出的代码,但是handles.plot_holds无论我拥有什么事实,我都不会更新guidata(hObject, handles)这是因为我将其用作函数吗?如果我只是通过start_hh_Callback本身而不是通过start_ss_Callback它,它将更新。但是,如果我在像start_ss_Callback这样的回调中使用它,则不会更新。

我希望我的问题很清楚,如果您需要澄清,请告诉我。

function start_hh_Callback(hObject, eventdata, handles)
% hObject    handle to start_hh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of start_hh as text
%        str2double(get(hObject,'String')) returns contents of start_hh as a double

axes(handles.axes1)
if isempty(handles.plot_holds)
    cla
    plot_button_Callback(hObject, eventdata, handles)
else
    % in the event the time is changed after more than 1 plot is held then
    % the additional plot times will be re evaluated for each parameter and
    % the new indicies will take into affect.
    myParams = get(handles.load_params_button,'string');
    mystartDD = str2num(get(handles.start_dd,'string'));
    mystartHH = str2num(get(handles.start_hh,'string'));
    mystartMM = str2num(get(handles.start_mm,'string'));
    mystartSS = str2num(get(handles.start_ss,'string'));

    myendDD = str2num(get(handles.end_dd,'string'));
    myendHH = str2num(get(handles.end_hh,'string'));
    myendMM = str2num(get(handles.end_mm,'string'));
    myendSS = str2num(get(handles.end_ss,'string'));

    startFromStart =  (mystartDD)*60*60*24 + (mystartHH-handles.startHour)*60*60 ...
        + (mystartMM-handles.startMinute)*60 + (mystartSS-handles.startSecond);
    endFromStart =  (myendDD)*60*60*24 + (myendHH-handles.startHour)*60*60 ...
        + (myendMM-handles.startMinute)*60 + (myendSS-handles.startSecond);

    iStart = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time > (startFromStart+handles.startTimeOffset),1);
    iEnd = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time > (endFromStart+handles.startTimeOffset),1);
    if isempty(iEnd)
        iEnd = length(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time);
    end

    cla
    hold off

    plot(handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Time(iStart:iEnd),...
        handles.load.dataGST.(handles.myParams{handles.plot_holds(1,1)}).(handles.myPackets{handles.plot_holds(1,1)}{handles.plot_holds(1,2)}).Data(iStart:iEnd))

    grid minor
    box on

    handles.plot_holds(1,3) = iStart;
    handles.plot_holds(1,4) = iEnd;

    if size(handles.plot_holds,1)>1
        hold all
        for ii = 2:size(handles.plot_holds)
            iStart = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time > (startFromStart+handles.startTimeOffset),1);
            iEnd = find(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time > (endFromStart+handles.startTimeOffset),1);
            if isempty(iEnd)
                iEnd = length(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time);
            end
            plot(handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Time(iStart:iEnd),...
                handles.load.dataGST.(handles.myParams{handles.plot_holds(ii,1)}).(handles.myPackets{handles.plot_holds(ii,1)}{handles.plot_holds(ii,2)}).Data(iStart:iEnd))
            handles.plot_holds(ii,3) = iStart;
            handles.plot_holds(ii,4) = iEnd;
        end
    end
end

legend(handles.myLegends{1:length(handles.myLegends)})

guidata(hObject, handles);
塞巴斯蒂安

在任何修改句柄的函数之后,您将不得不再次加载句柄:

% this modifies and writes the handles to the guidata
start_hh_Callback(hObject, eventdata, handles);
% now read back the updated value
handles = guidata(hObject);

另外,您也可以使handles回调的返回值。通常,在将其真正用作回调时,将其忽略;当将其用作“正常”函数时,它将避免需要从中重新读取guidata您的代码如下所示:

handles = start_hh_Callback(hObject, eventdata, handles);

将您的回调重新定义为:

function [handles] = start_hh_Callback(hObject, eventdata, handles)
...
end

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用回调函数“每个”时出错

来自分类Dev

在Python中使用回调时出错

来自分类Dev

使用回调时如何发送int?

来自分类Dev

如何使用回调

来自分类Dev

MATLAB-使用回调更新表面图的颜色

来自分类Dev

在仪表板,我怎么使用回调更新图形时,选择一个单选按钮?

来自分类Dev

使用回调时无法在KOA中设置标头

来自分类Dev

Node&Express:使用回调时发送404响应

来自分类Dev

当绑定函数可以删除时如何安全使用回调

来自分类Dev

承诺我在使用回调时返回挂起状态

来自分类Dev

Node&Express:使用回调时发送404响应

来自分类Dev

未使用回调时函数返回未定义,使用回调时,JS 表示函数未定义

来自分类Dev

了解如何使用回调

来自分类Dev

.off无法使用回调

来自分类Dev

boost :: python:使用回调

来自分类Dev

如何使用回调机制?

来自分类Dev

了解如何使用回调

来自分类Dev

使用回调导入模块

来自分类Dev

在函数回调中使用回调

来自分类Dev

多处理时不调用回调

来自分类Dev

如何在不使用 eval() 的情况下使用回调更新函数包装中的条件?

来自分类Dev

setTimeout是使用回调时避免stackoverflow的有效方法吗?

来自分类Dev

在快速路由中使用回调函数时的未定义参数

来自分类Dev

使用回调时express.js请求/响应对象的生命周期

来自分类Dev

使用回调函数时,jQuery表单提交不起作用

来自分类Dev

使用回调函数作为Component @Input()时的Angular2未定义对象属性

来自分类Dev

当我使用Realm执行异步事务时,永远不会调用回调

来自分类Dev

不使用回调时的结果不确定。Nodejs,Express和SQL Server Express

来自分类Dev

当我可以简单地调用它们时,为什么要使用回调函数?

Related 相关文章

热门标签

归档