Creating a Dropdown menu by listing the variables from model workspace, editing them in UITable element and then saving back to model workspace

4 次查看(过去 30 天)
Hello Together,
I am working on an interactive application using App Designer (MATLAB R2017b). I am doing the following sequence of operations:-
  1. Listing all the variables from the Model workspace and assigning them in the dropdown menu usinng the following callback function-
mdlWks = get_param('DummyModel','ModelWorkspace');
save(mdlWks,'Model_Workspace.mat');
load Model_Workspace.mat;
vars = evalin(mdlWks, 'whos');
cell_array = cell(size(vars));
for i=1:length(vars)
cell_array{i} = vars(i).name;
end
app.WksVarsDropDown.Items = cell_array;
2. Next, If I click on any of the items from the drop down menu, the value of that item should be displayed in the UITable. Now, having displayed the value of the variable, I want to have te flexibility to edit the value. For this, I am using the following callback function ;-
mdlWks = get_param('DummyModel','ModelWorkspace');
vars = evalin(mdlWks, 'whos');
cell_array = cell(size(vars));
for i=1:length(vars)
cell_array{i} = vars(i).name;
end
WksVars = app.WksVarsDropDown.Value;
assignin(mdlWks,'WksVars',WksVars);
for i = 1 : length(vars)
switch WksVars
case cell_array{i}
A = evalin(mdlWks,cell_array{i});
paramObj = A.Value;
app.UITable2.Data = paramObj;
ncols = size(app.UITable2.Data,2);
app.UITable2.ColumnEditable = true(1,ncols);
end
end
3. Having edited the value of one or more variables from the UITable element, I want is to save the changes to model workspace. For saving the model workspace I am using a pushbutton element, callback function for which is mentioned below.
mdlWks = get_param('DummyModel','ModelWorkspace');
mdlWks.DataSource = 'MAT-File';
mdlWks.FileName = 'Parameters_Model_Wks';
saveToSource(mdlWks);
The model workspace is not getting updated as per the changes, neither it is throwing any waring or error so that I can understand the issue.
I am not able to proceed further. Please guide me on this.
Thanking you in Anticipation!

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dependency Analysis 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by