How can I use quadprog in Simulink?

조회 수: 22 (최근 30일)
Saleh Msaddi
Saleh Msaddi 2020년 3월 23일
댓글: Saleh Msaddi 2021년 3월 8일
Hello everyone,
I am using quadprog in a MatLab function in Simulink. When I run the simulation, I get the following error "Function 'quadprog' not supported for code generation". My purpose is running a simulation and interpreting the results, I don't want to generate any code from the model.
Any suggestions on how I can solve this issue?
Thanks in advance.

채택된 답변

Saleh Msaddi
Saleh Msaddi 2020년 3월 23일
편집: Saleh Msaddi 2020년 3월 23일
It appeared that most of the Optimization Toolbox functions supported with Embedded MATLAB, and quadprog is one of these upsupported functions. Since I am not interested in code generation, I figured out that I can use the following command in my function block, and it works perfectly!
coder.extrinsic('quadprog');
  댓글 수: 4
Syed Ahmad Nadeem
Syed Ahmad Nadeem 2020년 6월 21일
Thank you for the information Saleh. I tried using the code you mentioned above to work with the quadprog function in matlab embedded function. On using it I a receive another set of errors as:
'inner matrix dimensions must agree'
Simulink cannot determine sizes and/or types of the outputs for block 'linear_model_check/MPC controller' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
I tried exploring these errors further and it seems these generate from the command statement where I try to assign the outputs of 'quadprog' function to some variable name. If you could point in some direction, it would be really helpful. I am using Matllab 2018a, and trying to avoid the upgradation to 2020a.
Saleh Msaddi
Saleh Msaddi 2020년 6월 21일
Dear Syed, try using the signal speicifer to specify the quadprog output signal properties. Check https://www.mathworks.com/help/simulink/slref/signalspecification.html
Regards

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

추가 답변 (1개)

Mary Fenelon
Mary Fenelon 2020년 4월 21일
Code generation support for quadprog was added in R2020a.
  댓글 수: 3
li gu
li gu 2021년 3월 8일
I want to ask why I upgrade matlab to 2020, but still report an error to show that this function cannot generate code?
Saleh Msaddi
Saleh Msaddi 2021년 3월 8일
Use the following function in the first beginning of your MATLAB Function,
coder.extrinsic('quadprog');
Also, make sure to use a "signal specification" block to specify the dimenasion of the signal produced by the quadprog function

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

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by