필터 지우기
필터 지우기

If the element of the bus is put as an input to the matlab function

조회 수: 2 (최근 30일)
가은 최
가은 최 2022년 4월 5일
답변: Yash Sharma 2023년 9월 15일
We designed simulink as shown in the picture above.
Matlab function wrote the following code, but it doesn't work.
How can we solve this error?
function y = fcn(u)
element.u1 = u.x;
element.u2 = u.y;
element.u3 = u.dy/dt;
y = 4 * element.u1 - 4 * element.u2 - 4 * element.u3;
end
Error
Property 'x' is not recognized as valid.
Function 'MATLAB Function' (#36.34.37), line 3, column 14:
"u.x"

답변 (1개)

Yash Sharma
Yash Sharma 2023년 9월 15일
Hi 가은 최,
I understand that you have elements in a bus, and you want to access these elements inside a MATLAB function block.
The DOT(.) notation you are currently using to access elements inside MATLAB function block only works with non-virtual busses and by default the Bus Creator block outputs virtual bus. To access elements from virtual bus you can use indexing. Change your code as follows:
function y = fcn(u)
element.u1 = u(1); % x
element.u2 = u(2); % y
element.u3 = u(3); % dy/dt
y = 4 * element.u1 - 4 * element.u2 - 4 * element.u3;
end
You can also convert your virtual bus to non-virtual bus by using “signal conversion” block, you will have to create Simulink bus object first.
Refer to the documentation below to get more information on how to convert virtual bus to nonvirtual bus.

카테고리

Help CenterFile Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by