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!