App Designer help with uitable
4 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(1 个)
Eric Delgado
2023-3-20
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!