本文介绍了保存来自可使用的Matlab GUI的用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个GUI(不使用GUIDE)我正在寻找一种方便用户输入数据的方法.我认为uitable将是理想的选择,除了我似乎无法弄清楚如何从表中存储用户输入.我宁愿不使用celleditcallback函数-理想情况下,我想使用保存"按钮或类似按钮一次将所有数据全部保存出来,有什么想法吗?表的代码(这是它自己的功能):

I'm creating a GUI (not using GUIDE)I'm looking for a convenient way for a user to enter some data. I figured uitable would be ideal except i can't seem to figure out how to store the user input from the table.I'd rather not use the celleditcallback function - ideally i'd like to save out the data all at once at the end using a save button or similar, any ideas?code for the table (this is within it's own function):

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');

预先感谢您的任何建议

推荐答案

我认为重要的是,在函数末尾以及将表数据分配给输出之前,需要一个waitfor(gcf).

I think the big thing is that you need a waitfor(gcf) at the end of your function and before you assign the table data to the output.

查看此示例:

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');

这样^^^是如何将输出变量分配给表值的方法

So that ^^^ is how you can assign output variables to your table values

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

Saving via button is very very easy. On your button callback, just do

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

希望有帮助!

这篇关于保存来自可使用的Matlab GUI的用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:53