Clear Filters
Clear Filters

Accessing Signal in MATLAB SLDD from bus editor

4 views (last 30 days)
I have a sldd which contains various simulink busses inside it, I wanted to access the signals which were present inside the busses so as to write a excel file from it.
Is there any way to do this?

Answers (1)

Vignesh
Vignesh on 11 Oct 2023
Hello Harsh Mittal,
I see that you are looking for a way to access the signals that are present inside a bus which are there in the Simulink Data Dictionary.
I found a similar question in the community where the usage of ‘arrayfun’ and ‘cellfun’ functions were suggested to edit the bus elements pragmatically and I suggest you refer the same. Please use the following question to view the question.
Kindly refer to the following example code with key parts key parts to accessing the element names, please modify this code to meet your requirements.
sldd_object = Simulink.data.dictionary.open('filename.sldd');
section = getSection(sldd_object, 'Design Data');
entries = find(section, '-value', '-class', 'Simulink.Bus');
% produce cell array of Simulink.Bus objects:
buses = arrayfun(@(x) getValue(x), entries, 'UniformOutput', false);
% produce a cell array of cell arrays of Simulink.BusElement objects:
elements = cellfun(@(x) x.Elements, buses, 'UniformOutput', false);
% produce a cell array of cell arrays of element names:
element_names = getElementNames(elements);
function names = getElementNames(arrayOfElements)
%%getElementNames returns a cell array of element names
function names = busElementNames(busElement)
if (length(busElement)<1)
errordlg('There is a bus with zero elements. Oops.')
elseif (length(busElement)==1)
names{1}{1} = busElement.Name;
else
names = arrayfun(@(x) x.Name, busElement, 'UniformOutput', false);
end
end
names = cellfun(@busElementNames, arrayOfElements, 'UniformOutput', false);
end
I hope this helps you in accessing the bus elements from SLDD.

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!