mulitlevel structure does not work with simulink bus
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I need to work with highly complex structures in simulink. I have a main m-file in which I create a bus object in the main workspace:
main.sub(1).a = 2;
main.sub(1).b = 3;
main.sub(2).b = 4;
bus1 = Simulink.Bus.createObject(main);
In simulink I have a matlab function, that looks like this:
function main = set_new_structure_values(u)
main.sub(1).a = u(1);
main.sub(1).b = u(2);
main.sub(2).b = u(3);
end
In the bus editor, I set "slBus1" as name and the type bus for the function output.
But it just doesnt work, I get errors like this: "Errors occurred during parsing of MATLAB function 'MATLAB Function'(#48)" It seems to has something to do with the index "(i)", but I am not sure.
I dont know why this doesnt work. Documentation is not very helpfull here. Does anyone have an idea? Thanks in advance.
0 个评论
回答(1 个)
Tamir Suliman
2023-2-23
编辑:Tamir Suliman
2023-2-23
check the input and output data types of the MATLAB function block. The input should be a vector of the same length as the number of fields in the bus, and the output should be a bus of the same type as the bus object you created in the main m-file.
make sure that the bus object is defined correctly in the main m-file. Make sure that the names and data types of the bus elements match those in the MATLAB function.
function out = set_new_structure_values(in)
out.sub(1).a = in(1);
out.sub(1).b = in(2);
out.sub(2).b = in(3);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!