Reputation: 1
I am trying to save the User input in app designer(MATLAB). I have created an empty struct, but I am unable to figure out where the items in the Listbox are being saved. With Matlab, a matrix is usually created and one can make certain UI components persistent so that, but that doesnt seem to be the case for App designer. I have attached a copy of the code, this isnt the complete code but rather the area for the listbox
properties (Access = public)
myStruct = struct()
end
% Callbacks that handle component events
methods (Access = private)
% Callback function: NEXTButton_4, WelcomeTab
function ButtonPushed(app, event)
app.TabGroup.SelectedTab = app.AgeTab
end
% Value changed function: ListBox
function ListBoxValueChanged(app, event)
value = app.ListBox.Value;
if strcmp(app.ListBox.Value ,'18-28')||strcmp(app.ListBox.Value ,'29-39')||strcmp(app.ListBox.Value,'40-50')||strcmp(app.ListBox.Value,'51-61')...
||strcmp(app.ListBox.Value,'62-72');
set(app.NEXTButton,'Enable','on');
Age = app.myStruct.Age;
end
Age = app.ListBox.Value;
% save('Age.mat',"Age")
% save('Dummyfile.mat', '-struct', myStruct)
% for i = 1:numel(app.ListBox.Items)
% index(i) = isequal(app.ListBox.Value{1}, [app.ListBox.ItemsData{i}]);
% end
% idx = find(index); % Find indice of nonzero element
% ItemName = app.ListBox.Items{idx}
i have tried to create an index, but it didn't work.
Upvotes: 0
Views: 420
Reputation: 5190
I'm not sure I understand the question correctly, but, if you want to save the values of all selected items you can:
Add two properties
to the app:
cellarray
in which to store the value of the selected items; if you need to save only it, you don't need a structproperties (Access = public) Selected_items = {} % Description n_ages; end
In the startupFcn
:
ListBoxValueChanged
will not catch the selection of it)function startupFcn(app) app.Selected_items = {}; app.ListBox.Value = {}; app.n_ages = 0; end
In the ListBoxValueChanged callback
:
function ListBoxValueChanged(app, event) value = app.ListBox.Value; app.n_ages = app.n_ages + 1; app.Selected_items{app.n_ages} = value; Selected_Items=app.Selected_items; save('SEL_ITEMS.mat','Selected_Items'); end
Note: you can easily adapt the code of the ListBoxValueChanged callback above to take into acount the if
conditions
Upvotes: 0