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

5 Ansichten (letzte 30 Tage)
Anju Mohokar
Anju Mohokar am 11 Nov. 2019
Beantwortet: Jatin am 28 Aug. 2024
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 .

Antworten (1)

Jatin
Jatin am 28 Aug. 2024
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:

Kategorien

Mehr zu Composite Interfaces finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by