Looking for data structure ideas for App Designer GUI used to set simulation inputs
Hi all,
I’m looking for advice or ideas on how to manage data structures.
I have an App Designer GUI for a user to input data, which is then written to a save file (.mat). This file is loaded into an agent-based Monte Carlo simulation.
The agents used in the simulation are unlimited in number, include multiple agent types, and each instance (for each agent type) stores multiple data classes (e.g., strings, doubles, Booleans, arrays, etc.)
Currently, the data flow in the GUI is: data input field -> Map Container object -> Cell Array in the input GUI.
And, when used by the sim, the data flow is: Cell Array -> Map Container object (in a loop) -> named variable (in a function called in the loop)
For example:
% Numeric input field callback in the data input GUI
app.GreenAgent_InputsMap(‘Var1’) = app.GreenAgent_Var1_InputField.Value;
% Write inputs map to cell array (by index) in the data input GUI, which is then saved to a .mat file
% (without the .app scope)
app.GreenAgent_InputsCells{n} = app.GreenAgent_InputsMap.keys();
app.GreenAgent_InputCells{n+1} = app.GreenAgent_InputsMap.values();
% In the simulation, the .mat file is opened (in a loop)
GreenAgent_InputsMap = containers.Map(GreenAgent_InputCells{n}, GreenAgent_InputCells{n+1});
GreenAgent_Var1 = GreenAgent_InputsMap(‘Var1’);
I use the Map Containers to: 1) use names (like a dictionary) rather than index position in a cell array; and 2) store multiple data types. I use the Cell Arrays to unpack data for each agent type iteratively.
There are too many variables in each agent type to outright name the variables individually, especially considering an unlimited number of each agent type can be created by the user. As is, I’m effectively creating 3 copies of each variable:
The App Designer input field (the input fields switch whenever a different agent of the same type is selected for editing)
The Map Container key/value pair (the Map Container is overwritten whenever a different agent of the same type is selected for editing)
The Cell Array where the data is ultimately stored and used by the sim (to support looping over an unlimited number of agents)
I’m wondering if there is a more elegant solution. For instance, it would be nice if each variable for an agent (i.e., in the Map Container) supported highlighting in the MATLAB editor to quickly find all the instances where that variable (‘Var1’ in the example code) is called and/or overwritten. I’ve thought about using structure arrays to take the place of the Map Containers and Cell Arrays, but that wouldn’t solve the highlighting limitation, and I’m not sure if that is the best approach either.
Thanks for reading to this point!Hi all,
I’m looking for advice or ideas on how to manage data structures.
I have an App Designer GUI for a user to input data, which is then written to a save file (.mat). This file is loaded into an agent-based Monte Carlo simulation.
The agents used in the simulation are unlimited in number, include multiple agent types, and each instance (for each agent type) stores multiple data classes (e.g., strings, doubles, Booleans, arrays, etc.)
Currently, the data flow in the GUI is: data input field -> Map Container object -> Cell Array in the input GUI.
And, when used by the sim, the data flow is: Cell Array -> Map Container object (in a loop) -> named variable (in a function called in the loop)
For example:
% Numeric input field callback in the data input GUI
app.GreenAgent_InputsMap(‘Var1’) = app.GreenAgent_Var1_InputField.Value;
% Write inputs map to cell array (by index) in the data input GUI, which is then saved to a .mat file
% (without the .app scope)
app.GreenAgent_InputsCells{n} = app.GreenAgent_InputsMap.keys();
app.GreenAgent_InputCells{n+1} = app.GreenAgent_InputsMap.values();
% In the simulation, the .mat file is opened (in a loop)
GreenAgent_InputsMap = containers.Map(GreenAgent_InputCells{n}, GreenAgent_InputCells{n+1});
GreenAgent_Var1 = GreenAgent_InputsMap(‘Var1’);
I use the Map Containers to: 1) use names (like a dictionary) rather than index position in a cell array; and 2) store multiple data types. I use the Cell Arrays to unpack data for each agent type iteratively.
There are too many variables in each agent type to outright name the variables individually, especially considering an unlimited number of each agent type can be created by the user. As is, I’m effectively creating 3 copies of each variable:
The App Designer input field (the input fields switch whenever a different agent of the same type is selected for editing)
The Map Container key/value pair (the Map Container is overwritten whenever a different agent of the same type is selected for editing)
The Cell Array where the data is ultimately stored and used by the sim (to support looping over an unlimited number of agents)
I’m wondering if there is a more elegant solution. For instance, it would be nice if each variable for an agent (i.e., in the Map Container) supported highlighting in the MATLAB editor to quickly find all the instances where that variable (‘Var1’ in the example code) is called and/or overwritten. I’ve thought about using structure arrays to take the place of the Map Containers and Cell Arrays, but that wouldn’t solve the highlighting limitation, and I’m not sure if that is the best approach either.
Thanks for reading to this point! Hi all,
I’m looking for advice or ideas on how to manage data structures.
I have an App Designer GUI for a user to input data, which is then written to a save file (.mat). This file is loaded into an agent-based Monte Carlo simulation.
The agents used in the simulation are unlimited in number, include multiple agent types, and each instance (for each agent type) stores multiple data classes (e.g., strings, doubles, Booleans, arrays, etc.)
Currently, the data flow in the GUI is: data input field -> Map Container object -> Cell Array in the input GUI.
And, when used by the sim, the data flow is: Cell Array -> Map Container object (in a loop) -> named variable (in a function called in the loop)
For example:
% Numeric input field callback in the data input GUI
app.GreenAgent_InputsMap(‘Var1’) = app.GreenAgent_Var1_InputField.Value;
% Write inputs map to cell array (by index) in the data input GUI, which is then saved to a .mat file
% (without the .app scope)
app.GreenAgent_InputsCells{n} = app.GreenAgent_InputsMap.keys();
app.GreenAgent_InputCells{n+1} = app.GreenAgent_InputsMap.values();
% In the simulation, the .mat file is opened (in a loop)
GreenAgent_InputsMap = containers.Map(GreenAgent_InputCells{n}, GreenAgent_InputCells{n+1});
GreenAgent_Var1 = GreenAgent_InputsMap(‘Var1’);
I use the Map Containers to: 1) use names (like a dictionary) rather than index position in a cell array; and 2) store multiple data types. I use the Cell Arrays to unpack data for each agent type iteratively.
There are too many variables in each agent type to outright name the variables individually, especially considering an unlimited number of each agent type can be created by the user. As is, I’m effectively creating 3 copies of each variable:
The App Designer input field (the input fields switch whenever a different agent of the same type is selected for editing)
The Map Container key/value pair (the Map Container is overwritten whenever a different agent of the same type is selected for editing)
The Cell Array where the data is ultimately stored and used by the sim (to support looping over an unlimited number of agents)
I’m wondering if there is a more elegant solution. For instance, it would be nice if each variable for an agent (i.e., in the Map Container) supported highlighting in the MATLAB editor to quickly find all the instances where that variable (‘Var1’ in the example code) is called and/or overwritten. I’ve thought about using structure arrays to take the place of the Map Containers and Cell Arrays, but that wouldn’t solve the highlighting limitation, and I’m not sure if that is the best approach either.
Thanks for reading to this point! data structures, map containers, cell arrays, app designer MATLAB Answers — New Questions