1

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

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
richyo1000
  • 190
  • 3
  • 16

1 Answers1

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!

Shaun314
  • 3,191
  • 4
  • 22
  • 27
  • Thanks! I had no idea about the waitfor function, i think this will do the trick! cheers! – richyo1000 Jun 26 '13 at 14:16
  • I just realized, you may need to save the variable in something other than a handles object, becuase when you close the fig, you close the uitable. I know you don't want to edit the editcell callback, but all you would have to do is say, outputTable=get(myTable,'Data'); Then make your output simply "outputTable". You still do need the waitfor command though. – Shaun314 Jun 26 '13 at 14:19