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

2 views (last 30 days)
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!

Answers (0)

Categories

Find more on Simulink Environment Customization in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!