How to programmatically arrange signals in Bus Creator and Bus Selector blocks alphabetically?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 17 Sep. 2024
Bearbeitet: MathWorks Support Team
am 9 Okt. 2024
How can I programmatically arrange input signals to the Bus Creator block and output signals from the Bus Selector block alphabetically?
Akzeptierte Antwort
MathWorks Support Team
am 7 Okt. 2024
Bearbeitet: MathWorks Support Team
am 9 Okt. 2024
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 place 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:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Load Signal Data for Simulation finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!