Clear Filters
Clear Filters

Access the Simulink.Bus elements from cell array of Bus objects.

14 views (last 30 days)
I have cell array containing cell arrays of bus objects with its simulink.bus elements. I want to search the simulink bus element in thos cell with the name of sub bus.
For ex: if I have "Bus" cell array>>with "Sub_Bus" cell arrays>> and Signal 1.simulink bus element in it.
I want to search "signal 1" in Cell "Bus" and also want "sub_bus" name into which signal 1 is placed using matlab code .

Answers (1)

Jatin Singh
Jatin Singh on 28 Aug 2024 at 5:23
As per my understanding you have a cell array of cell arrays which contains Simulink.bus elements and you want to search for a signal and wants the sub_bus name into which the signal is placed.
I am assuming that the main cell array contains arrays of sub_bus” which is also a cell array of Simulink.bus elements and the sub_bus name is indexed according to the index of the sub_bus array in the main cell array.
You can find the “sub_bus” name and signal index with the help of the following MATLAB function which takes main cell array and signal name to search and returns the sub-bus name and signal index as output, I’m assuming the main cell array is an array of cell arrays which contains Simulink.bus elements.
function [subBusName, signalIndex] = findSignalInBus(busCellArray, signalName)
% Initialize outputs
subBusName = '';
signalIndex = -1;
% Iterate over each cell in the main bus cell array
for i = 1:length(busCellArray)
subBusCellArray = busCellArray{i};
% Iterate over each sub-bus cell array
for j = 1:length(subBusCellArray)
% Check if the name of the bus element matches the signal name
if strcmp(subBusCellArray{j}.Name, signalName)
subBusName = sprintf('Sub_Bus_%d', i); % Assuming sub-bus naming convention
signalIndex = j;
return;
end
end
end
end
You can refer to the below documentation for working with Simulink.Bus object:

Categories

Find more on Composite Interfaces in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!