【问题标题】:saving user input from uitable matlab GUI?从合适的matlab GUI保存用户输入?
【发布时间】:2013-06-23 17:21:32
【问题描述】:

我正在创建一个 GUI(不使用 GUIDE) 我正在寻找一种方便的方式让用户输入一些数据。我认为 uitable 将是理想的,但我似乎无法弄清楚如何存储表格中的用户输入。 我宁愿不使用 celleditcallback 函数 - 理想情况下,我想在最后使用保存按钮或类似按钮一次性保存所有数据,有什么想法吗? 表格的代码(这是在它自己的函数中):

dat =  {0,  0,  0, true;...
        0,  0,  0, true;...   
        0,  0,  0, true;};
columnname =   {'x-pos', 'y-pos', 'dimns', 'Include?'};
NC = numel(columnname);
rowNumber = zeros(NR,NC);
columnformat = {'numeric', 'numeric', 'numeric','logical'};
columneditable =  [true true true true true];
rowname = {'Dat1','Dat2','Dat3'};
Config = uitable('Units','normalized','Position',[0 0 0.2 0.4],...
            'Data', dat,... 
            'ColumnName', columnname,...
            'ColumnFormat', columnformat,...
            'ColumnEditable', columneditable,...
            'RowName',rowname);
cell2mat(dat(:,1:3));
gh =get(Config,'Data');

提前感谢您的任何建议

【问题讨论】:

    标签: matlab user-interface user-input matlab-uitable


    【解决方案1】:

    我认为重要的是,在函数结束时以及将表数据分配给输出之前,您需要一个 waitfor(gcf)。

    看看这个例子:

    function [out1]=myGUIwithATable(inputs..)
    
    myTable=uitable(.......)
    
    waitfor(gcf) 
    
    %This command will wait until you close the GUI before doing the code after 
    % it. We use this to allow you to enter all your data and whatnot, then once  
    % you close the fig, it will execute your save commands
    
    out1=get(myTable,'Data');
    

    这样 ^^^ 是您可以将输出变量分配给表值的方式

    通过按钮保存非常简单。在您的按钮回调中,只需执行

    save('fileName.mat',get(myTable,'Data'))
    

    希望有帮助!

    【讨论】:

    • 谢谢!我不知道 waitfor 函数,我认为这可以解决问题!干杯!
    • 我刚刚意识到,您可能需要将变量保存在句柄对象以外的其他地方,因为当您关闭无花果时,您会关闭 uitable。我知道您不想编辑 editcell 回调,但您所要做的就是说 outputTable=get(myTable,'Data');然后让你的输出简单地“输出表”。你仍然需要 waitfor 命令。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 2014-11-26
    相关资源
    最近更新 更多