Hello,
As you can see from the photo I attached, I am trying to run a simulink model that uses MUX blocks, Matlab function block, and integrator in a feedback loop.
The code in the Matlab function is:
function y = fcn(u)
vta = u(1); vtb = u(2); vtc = u(3);
ea = u(4); eb = u(5); ec = u(6);
ia = u(7); ib = u(8); ic = u(9);
iLa = u(10); iLb = u(11); iLc = u(12);
R = 0.02; L = 0.04; RL = 3; LL = 0.01; C = 0.001;
de = (1/C)*[ia-iLa;ib-iLb;ic-iLc];
di = (1/L)*[vta-ea-R*ia; vtb-eb-R*ib; vtc-ec-R*ic];
diL = (1/LL)*[ea-RL*iLa; eb-RL*iLb; ec-RL*iLc];
y = [de;di;diL];
And the error is:
Could you please help me how to troubleshoot it? I think the issue has to do with the feedback loop but I don't know how to fix it.
Thank you

 채택된 답변

Simon Chan
Simon Chan 2022년 1월 21일

0 개 추천

Check the length of variable 'u'.
Looks like there is only 1 element inside variable 'u', but the function request to find the elements from #1 to #12 from 'u'.
Or could you post what is the content of 'u'?

댓글 수: 3

Milad Shojaee
Milad Shojaee 2022년 1월 21일
Thank you for the response
Variable 'u' should have 12 elements. 3 from the previous stage and 9 from the feedback loop. But I don't know why it only generates 1 element in its output. Based on "y = [de;di;diL]", it should generate a vector with 9 elements because de, di, and diL has 3 elements each.
It seems that generation of those elements in fcn output deponds on its inputs but the inputs are also dependent on the output elements!
Simon Chan
Simon Chan 2022년 1월 21일
So you need to think about to assign some initial values for those 9 elements before feeding into this function.
After you combine 3 elements obtained from the previous stage and 9 dummy feedback elements. The function should work properly.
Milad Shojaee
Milad Shojaee 2022년 1월 21일
I added initial conditions and it worked. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 1월 21일

1 개 추천

Those solid markings appear to me to indicate that you are using a Simulink Bus Creator https://www.mathworks.com/help/simulink/slref/buscreator.html
If you were concatenating the elements into a vector, you would see hollow white blocks instead of filled blocks; see https://www.mathworks.com/help/simulink/slref/vectorconcatenate.html
You can either switch to using vector concatenate and have the signal be a vector, or before you send the bus into the function block you can convert to vector; https://www.mathworks.com/help/simulink/slref/bustovector.html

댓글 수: 1

Milad Shojaee
Milad Shojaee 2022년 1월 21일
Thank you for your reply. I replaced the Bus Creator with Vector concatenate block but it did not make any difference. I still had the same issue. However, as Simon suggested, I added initial conditions to the feedback loop and it worked.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

질문:

2022년 1월 21일

댓글:

2022년 1월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by