graphical visualization of input parameters collected in a struct/array

6 ビュー (過去 30 日間)
SA-W
SA-W 2023 年 9 月 8 日
コメント済み: SA-W 2023 年 9 月 8 日
My simulation depends on a whole bunch of input parameters that control various features of the simulation.
I decided to group these parameters in a struct and pass this script to my main.m script.
% .m file that contains all parameters and calls main program
params = struct;
params.input1 = val1;
params.input2 = val2;
...
% many more parameters (bundled in substructs)
% call main function
main(params)
% end of .m file containing parameters
This approach works, however, I am looking for a better way to alter/visualize the parameters.
For instance, there is the `typeeditor` in Simulink to visualize inputs in a nice manner.
Is there a way to visualize all my parameters in a table-like structure, similar to what typeeditor does?
I am also open for alternatives of course!
Thank you!

回答 (2 件)

Shoresh Shokoohi
Shoresh Shokoohi 2023 年 9 月 8 日
To visualize and manage a large set of parameters in MATLAB more conveniently, you can utilize several built-in MATLAB tools and features, such as creating a parameter table or using the `uitable` (UI Table) component for a graphical user interface (GUI). Here's how you can approach this:
Option 1: Parameter Table
You can create a parameter table using MATLAB's built-in data structures, such as a `table`. This allows you to store and organize your parameters in a structured way and provides easy visualization. Here's an example of how to create a parameter table:
```matlab
% Create a table with your parameters
paramTable = table(val1, val2, ...);
% Rename the table variables (optional, for better visualization)
paramTable.Properties.VariableNames = {'Input1', 'Input2', ...};
% Display the parameter table
disp(paramTable);
```
This code will display a table in the command window with your parameter values.
Option 2: GUI with `uitable` (UI Table)
If you want a more interactive and user-friendly way to visualize and edit your parameters, you can create a graphical user interface (GUI) using MATLAB's App Designer or GUIDE. You can include a `uitable` component in your GUI to display and edit the parameter values.
Here's a simplified example of creating a GUI with a `uitable`:
```matlab
% Create a figure for the GUI
fig = uifigure('Name', 'Parameter Editor');
% Create a UI table to display parameters
paramTable = uitable(fig);
paramTable.Position = [50, 50, 300, 200]; % Adjust the position and size
paramTable.Data = [val1; val2]; % Initialize data
% Add column names (optional)
paramTable.ColumnName = {'Input1', 'Input2'};
% Create a "Save" button to save changes
saveButton = uibutton(fig, 'push', 'Text', 'Save', 'Position', [50, 10, 70, 30]);
saveButton.ButtonPushedFcn = @(btn, event) saveParameters(paramTable.Data);
% Define a function to save the updated parameters
function saveParameters(updatedData)
% Update your parameters with the new values in updatedData
val1 = updatedData(1);
val2 = updatedData(2);
% ...
disp('Parameters saved.');
end
% Run the GUI
```
This code creates a basic GUI with a `uitable` that allows you to visualize and edit parameter values and a "Save" button to save changes.
You can customize the GUI further to suit your needs, including adding more parameters, handling errors, and saving/loading parameters from files if necessary.
Choose the option that best fits your requirements, whether it's a simple parameter table or a more interactive GUI with a `uitable`. Both options provide a more user-friendly way to manage and visualize your parameters compared to a script.
  1 件のコメント
SA-W
SA-W 2023 年 9 月 8 日
How do I run the gui? You mentioned this as the last step.

サインインしてコメントする。


Fangjun Jiang
Fangjun Jiang 2023 年 9 月 8 日
Use the built-in variable editor is sufficient to visualize struct array. Just run this at the Command Window
open params

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by