How do I make signal names coming from linked subsystems unique?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a model the uses a large number of duplicates of a linked subsystem (created in a custom library). Each of these subsystems has a few output signals, for example "voltage", "current".
I've been struggling to find a way to give these signals unique names based on their subsystem - for example sub1.voltage, sub2.voltage..
The subsytems are masked, each with a unique name and refernce number (eg name: sub1, subsystemNumber: 1), but I can't find I way to implement either of these within the signal names.
I've also tried playing around with the bus creator, using one for all "current" signals and one for all "voltage" signals. It currenlty gives a warning and appends "(signal #)" for unique names, but I'm assuming this will become a problem when my model grows. I'm considering reorganizing my bus creators one for each subsystem rather than signal type, but this seems cumbersome for comparing signals later on.
Any suggestions?
I don't have much coding experience- I'm searching for a solution within the model rather than by programming if possible.
0 comentarios
Respuestas (1)
Nithin
el 11 de Feb. de 2025
If you want a simple way to change the names of output signals from 'signal_name' to 'subsys_name.signal_name', you can use the script below:
% get the list of subsystems with a specific mask type, replace
% 'your_mask_name' with the mask type you set.
subsystems = find_system('your_model_name', 'BlockType', 'SubSystem', 'MaskType', 'your_mask_type');
% iterate across each subsytem
for i = 1:length(subsystems)
% get the subsytem name (to be used to concatinate to the signal
% names)
subsystemName = get_param(subsystems{i}, 'Name');
% get the outports inside the subsystem (to get the names of the signals connected)
outports = find_system(subsystems{i},'LookUnderMasks','all', 'SearchDepth', 1, 'BlockType', 'Outport');
%get the signals connected to the subsystem (to be renames)
outLines = get_param(subsystems{i},'LineHandles');
%iterate through the outports
for j = 1:length(outports)
% get the signal names
outport_j = get_param(outports{j},'LineHandles');
signalName = [subsystemName, '.', get_param(outport_j.Inport, 'Name')];
% set the outgoing signal names with the updated name
set_param(outLines.Outport(j), 'Name', signalName);
end
end
Ensure that you apply a consistent mask type to all the subsystems you want to target, and replace 'your_mask_type' in the code with the mask type you've set.
If you're looking for alternative approaches without using code, organize your signals using Bus Creators for each subsystem. This method allows each bus to have a unique name based on the subsystem. However, this can become cumbersome if the size of your model increases.
It is always reccomended to utilize some code to acheive these kind of tasks, to reduce your effort.
I hope this resolves your query.
0 comentarios
Ver también
Categorías
Más información sobre Subsystems en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!