How to list of input, output, signals and its data types used in the simulink model?

48 views (last 30 days)
How to print the list of input, output, signals and its data types used in the simulink model? "Model data editor" under modelling tab helps in viewing and editing the signals and its data types but how do we print them all separately to a csv/xlsx file? Could anyone please help me that process?

Accepted Answer

R
R on 10 May 2024
The Data Import/Export pane of the Configuration Parameters dialog box includes parameters that configure options for exporting output, signal, and state data from simulations. Refer to the following documentation for more information.
Check the options in the Save to workspace or file section according to your workflow and run the simulation. Once the variables are saved to workspace, you can export them to an excel file. Refer to the following MATLAB Answer to understand how to save workspace variables to an excel file:

More Answers (1)

Avni Agrawal
Avni Agrawal on 10 May 2024
I understand that you are trying to print the list of inputs, outputs, signals, and their data types used in a Simulink model to a CSV/XLSX file, you can use MATLAB scripting to access the model's information programmatically and then write this information to a file. Simulink provides a rich API for interacting with models, including accessing their components and properties.
Here is the code snippet to achieve this:
% Example MATLAB Script to Extract Signal Information from a Simulink Model and Write to CSV
modelName = 'your_model'; % Replace with your Simulink model name
load_system(modelName);
% Find all blocks that have ports (adjust the search to fit your needs)
blocks = find_system(modelName, 'FindAll', 'on', 'type', 'block');
% Initialize a table to hold the data
data = table({}, {}, {}, {}, 'VariableNames', {'BlockName', 'BlockType', 'PortType', 'DataType'});
% Loop through the blocks to get information
for i = 1:length(blocks)
blockName = get_param(blocks(i), 'Name');
blockType = get_param(blocks(i), 'BlockType');
% For each block, you may need to identify if it's an input, output, or signal
% and get its data type. This is a simplified example.
if isprop(handle(blocks(i)), 'CompiledPortDataTypes') % Check if property exists
portDataTypes = get_param(blocks(i), 'CompiledPortDataTypes');
if isfield(portDataTypes, 'Outport') % Example: Check for Outport data type
dataType = portDataTypes.Outport{1}; % Simplified: Assuming first outport
data = [data; {blockName, blockType, 'Outport', dataType}];
end
end
end
% Write the table to a CSV file
writetable(data, 'BAmodel_data.csv');
% Optionally, write to an XLSX file
writetable(data, 'BAmodel_data.xlsx');
I hope this helps!

Community Treasure Hunt

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

Start Hunting!