App Designer help with uitable

4 views (last 30 days)
ilia beloglazov
ilia beloglazov on 19 Mar 2023
Commented: ilia beloglazov on 22 Mar 2023
But now there is a problem that I don’t understand how to solve, I stopped sleeping and eating :crazy:
I am writing a program in the App Designer and this is the task
The button opens a figure and in it a table where I load different coefficients
The user can change these coefficients and at the end presses the save button. As a result, this table must be stored in the workspace so that the new values can be used in the calculation. And now I just can not save this table
load tableCmHn.mat % load my table
% create shape
fig = uifigure('Name','Hydro parameters','Position',[30 30 550 200]);
% create table
uit = uitable(fig);
uit.Position = [20 100 500 80];
uit.ColumnName = {'C2H6','C3H8','C4H10','C5H12','C2H4','C2H2'};
uit.RowName = {'m','n'};
uit.Data = CmHn;
uit.ColumnEditable = true;
newTable = uit.Data
btn = uibutton(fig,'push','Position',[420 60 100 22],'ButtonPushedFcn', @(btn,event) ButtonPushed1(btn,newTable));
btn.Text = 'Save';
but at this stage there is a problem
1. how to save the table?
save('tableCmHn.mat',newTable)
2. how to create a callback with the newTable parameter?
ButtonPushed1(btn,newTable)

Answers (1)

Eric Delgado
Eric Delgado on 20 Mar 2023
Why do you have to store in the workspace the edited table so that the new values can be used in the calculation?! Do you have a script and call it from Matlab prompt after the editing process in AppDesigner?
You can use assignin (https://www.mathworks.com/help/matlab/ref/assignin.html) to perform this operation... but I think you should not use the Workspace Base of Matlab, but just transform your script in a function and call it, passing your edited table (app.UITable.Data) to your new function.

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!