Accessing Signal in MATLAB SLDD from bus editor
9 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Vignesh
2023-10-11
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.
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!