Borrar filtros
Borrar filtros

How to programmatically arrange signals in Bus Creator and Bus Selector blocks alphabetically?

9 visualizaciones (últimos 30 días)
How to programmatically arrange input signals to the Bus Creator block and output signals from the Bus Selector block alphabetically?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 18 de Sept. de 2024 a las 0:00
Editada: MathWorks Support Team el 18 de Sept. de 2024 a las 11:30
There is no exact API to do such rearrangement, however, you can refer to the below example code to create your own script to achieve such rearrangement:
% Load the Simulink model model = 'test'; load_system(model); % Specify the Bus Creator block path busCreatorBlock = strcat(model, '/Bus Creator'); % Get the InputsString property of the Bus Creator block inputsString = get_param(busCreatorBlock, 'InputsString'); % Split the InputsString into individual signal names signalNames = strsplit(inputsString, ','); % Trim any whitespace from signal names signalNames = strtrim(signalNames); % Sort the signal names alphabetically sortedSignalNames = sort(signalNames); % Join the sorted signal names back into a comma-separated string sortedInputsString = strjoin(sortedSignalNames, ','); % Set the InputsString property with the sorted signal names set_param(busCreatorBlock, 'InputSignals', sortedInputsString); % Auto arrange the system Simulink.BlockDiagram.arrangeSystem(model); % Save and close the model save_system(model);
% Sort Bus Selector OutputSignals. % Assume Bus selector block is selected in canvas. % or pass the proper handle in places of 'gcbh' % Get the output signals as a string sig = get_param(gcbh, 'OutputSignals'); % Split the string into individual signal names signalList = split(sig, ','); % Trim any whitespace from signal names signalList = strtrim(signalList); % Sort the signal names alphabetically sortedSignalList = sort(signalList); % Concatenate the sorted signal names back into a single string sortedSig = strjoin(sortedSignalList, ','); % Display the sorted output signals disp(sortedSig); % set sortedSig to block handle set_param(gcbh, 'OutputSignals', sortedSig);
Arranging the input signals in a Bus Creator block would result in the misalignment of signals and associated blocks in the Simulink model. In such cases, you use Simulink.BlockDiagram.arrangeSystem to improve the layout of the specified block diagram by realigning, resizing, and moving blocks and straightening signal lines.
Please refer to the below link to know more details about the same:
Improve layout of block diagram:

Más respuestas (0)

Categorías

Más información sobre Load Signal Data for Simulation en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by