saving user input from uitable matlab GUI?

我们两清 提交于 2019-12-11 08:32:04

问题


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

Thanks in advance for any advice


回答1:


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.

Check out this example:

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

Hope that helps!



来源:https://stackoverflow.com/questions/17322291/saving-user-input-from-uitable-matlab-gui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!