uitable create modify and save

14 views (last 30 days)
Hello,
I have a 2D table and I would like to display this table and select some of lines of this table. I think the best is to create another column in my table set at 0 and when I want to select some line, I modify 0 to 1. After, I want to close the window (with a button) and retrieve the table (modified) in my Matlab workspace.
For that I choose to create an uitable. But I did not find how to :
  • Create another column to select the lines I want.
  • Create a uitable I can close with a button
  • Retrieve the table with the last column.
Thanks,
Pierre
  1 Comment
Mohammad Sami
Mohammad Sami on 21 Jan 2020
Just add an extra column to your data, then set as the Data property of the uitable.
After you are done with the updates, retreive the Data property to see what was selected.
% change yourdata to your variable name . type is table
yourdata.lastcol = false(height(yourdata),1);
f = uifigure('CloseRequestFcn',@(varargin)uiresume(gcbf));
editcols = false(1,width(yourdata));
editcols(end) = true;
t = uitable(f,'Data',yourdata,'ColumnEditable',editcols);
uiwait(f); % this will block until the figure is closed.
updatedata = t.Data;
close(f);
delete(f);

Sign in to comment.

Answers (1)

Payas Bahade
Payas Bahade on 24 Jan 2020
Hi Pierre-François,
I have created a demo App in App Designer which can be used to retrieve selected lines from given table. Refer to the .mlapp file in attachment.
Instead of making use of ‘0’ or ‘1’, I have used a separate checkbox column to select the rows whose data needs to be retrieved in a variable ‘newTable’ in MATALB workspace.
Hope this helps!
  1 Comment
Pierre-François Bourdelle
Hello Payas,
Thanks for you code, it's really helpful.
Apparently you created a class with App Designer...
Now, after some calculations, I have the table I want to show. But how to integrate your class in my existing code?
Thanks
Pierre-François

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!