MATLAB Answers

How can I get this simple gui to allow the user to input data into a table, then save that input once they close the window?

6 views (last 30 days)
Chris Gnam
Chris Gnam on 5 Apr 2016
Commented: Chris Gnam on 6 Apr 2016
What I'd like to have happen is that the user defines the size of a square matrix (for instance, 2 x 2). Then a new window would pop up and ask them for the individual data points, and then they would input the values into the correct spots on a table of the right size. I have gotten this to work fine up until the point where I actually need to retrieve the data to be used later. I cannot seem to "save" the data the user inputs. Here is what I have so far:
input = char(inputdlg('Please enter the order of the square matrix you wish to enter:'))
n = str2num(input)
matrix_data = cell(n,n)
matrix_input = figure('MenuBar','none','ToolBar','none',...
'Name','Row Reduction Assistant','NumberTitle','off','Position', [400 350 300 300]);
matrix = uitable(matrix_input,'Data',matrix_data,...
'Position', [42 65 220 220],...
'ColumnWidth', {30},...
'FontSize', 15,...
A_data = get(matrix_data,'Data');
When I do this, I get the error message:
Error using get
Conversion to double from cell is not possible.
Error in Test_file (line 14)
A_data = get(matrix_data,'Data');
Please note that what I've got there isn't "neat" as far as GUI's go. I just threw together the basic structure, but I can't seem to figure out how to store the data.

Answers (1)

Walter Roberson
Walter Roberson on 6 Apr 2016
A_data = get(matrix,'Data');
  1 Comment
Chris Gnam
Chris Gnam on 6 Apr 2016
This was what I originally tried, however that also does not work. When I replace my line of code with yours, what I get is:
Error using matlab.ui.control.Table/get
Invalid or deleted object.
Error in Test_file (line 14)
A_data = get(matrix,'Data');
Any idea of another solution? Or what else can be done?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by