Access the Simulink.Bus elements from cell array of Bus objects.
14 次查看(过去 30 天)
显示 更早的评论
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 .
0 个评论
回答(1 个)
Jatin Singh
2024-8-28,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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Composite Interfaces 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!