【问题标题】:How to fade a pushbutton until tables are filled in GUI MATLAB如何在 GUI MATLAB 中填充表格之前淡化按钮
【发布时间】:2017-09-29 17:01:29
【问题描述】:

我有 3 个由 3 个按钮填充的表。我想通过按compute.pushbutton 对它们进行一些计算但首先我希望用户将所有数据插入表中,然后显示他/她的计算按钮。我关闭了计算按钮的可见性,然后编写这些代码

  1. 按钮 1 功能

     function pushbutton1_Callback(hObject, eventdata, handles)
    
     global mat_index;
     [Iname,Ipath]= uigetfile('*.xlsx','Select Index Excel File');
     mat_index = xlsread(strcat(Ipath,Iname));
     table_as_cell1 = num2cell(mat_index);
     set(handles.uitable1, 'Data', table_as_cell1);
    
  2. 按钮2功能

     function pushbutton2_Callback(hObject, eventdata, handles)
    
     global mat_length;
     [lng_name,lng_path]= uigetfile('*.xlsx','Select Length Excel File');
     mat_length = xlsread(strcat(lng_path,lng_name));
     table_as_cell2 = num2cell(mat_length);
     set(handles.uitable2, 'Data', table_as_cell2);  
    
  3. 按钮 3 功能

     function pushbutton3_Callback(hObject, eventdata, handles)
    
     global mat_coordinate;
     [cord__name,cord_path]=uigetfile('*.xlsx','Select coordinate Excel 
      File');
     mat_coordinate = xlsread(strcat(cord_path,cord__name));
     table_as_cell3 = num2cell(mat_coordinate);
     set(handles.uitable3, 'Data', table_as_cell3);
    

还有

  1. 计算按钮

    function pushbutton4_Callback(hObject, eventdata, handles)
    
      if(isstored(mat_length) && isstored(mat_index) && 
              isstored(mat_coordinate))
    {
        set(handles.pushbutton4,'visible','on');
    }
    

【问题讨论】:

    标签: matlab user-interface


    【解决方案1】:

    您可以跟踪哪些按钮被按下。将变量初始化为handles.ButtonsPressed = [false , false , false]。然后添加这个函数并在你的回调中调用它:

    function updateButtons(n , handles)
        % n is the latest button pressed
        handles.ButtonsPressed(n) = true;
        if all(handles.ButtonsPressed)
            set(handles.pushbutton4,'visible','on');
        end
    

    所以在你的pushbutton1 中你应该添加updateButtons(1 , handles)。


    你可以概括它: 初始化:
     handles.Buttons2Validate = [handles.pushbutton1 , ...
                                 handles.pushbutton2 , handles.pushbutton3];
     handles.ButtonsPressed(1 : numel(handles.Buttons2Validate)) = false;
    

    并修改检查功能:

    function updateButtons(hObject , handles)
        % hObject is the handle of the button pressed
        position = handles.Buttons2Validate == hObject;
        handles.ButtonsPressed(position) = true;
        if all(handles.ButtonsPressed)
            set(handles.pushbutton4,'visible','on');
        end
    

    【讨论】:

    • 所以你的意思是 MATLAB 没有我想的那么聪明?
    • 什么意思?如果不可见,则不能将可见性开/关代码放在 pushbutton4 中;用户将无法点击它,它永远不会变得可见!
    • 我明白了。我应该在哪里声明handles.ButtonsPressed?我应该将其声明为全局吗?
    • 您可以将ButtonsPressed(不带句柄)声明为全局,但最好使用句柄。有关如何Store or retrieve UI data 的更多信息
    猜你喜欢
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 2019-06-11
    • 2017-04-09
    • 2012-03-19
    • 1970-01-01
    • 2022-08-14
    • 2020-06-21
    相关资源
    最近更新 更多