从 matlab 中的总线对象创建结构

creating a structure from a bus object in matlab

我有一个包含元素的总线对象,然后每个元素的数据类型为原始数据类型 (uint8 single, uint16) 或数据类型为另一个总线对象。我想对此进行解析,但是当我使用嵌套函数时出现错误 'Function cannot be indexed using {} or .indexing',因为我需要使用工作区中的 bsu 对象。 这是我的代码:

function s_func_parse(component_name,counter)
length_bus=length(component_name.Elements);
for i=1:length_bus
primitive_component{1,counter}=strcat(component_name.Elements(i).Datatype,'.');
if(strcmp(component_name.Elements(i).Datatype,'uint8')~=1 || strcmp(component_name.Elements(i).Datatype,'single')~=1  || strcmp(component_name.Elements(i).Datatype,'uint16')~=1 || strcmp(component_name.Elements(i).Datatype,'uint32')~=1)
    new_component=char(busobject.Elements(i).Datatype);
    s_func_parse(new_component,counter);
else
    primitive_component{1,counter}=strcat(primitive_component,busobject.Element(i));
end; 
end;
assignin('base', 'primitive_component', primitive_component);
end

其中 component_name 是主要的总线对象,计数器确定我拥有的原语总数以及我已经知道的这个值。

目前我无法解决这个问题,所以我想到将总线对象转换为一个包含所有数据的结构。可能吗?

也可以使用 matlab 内置函数从总线创建结构

structFromBus = Simulink.Bus.createMATLABStruct(busSource)