CVX and Simulink Problem

Hello,
I’m trying to use cvx for a SDP online optimization , i write the code in an embedded matlab function but when i run the simulink file, i got the following error:
Function ‘iscellstr’ is not supported for code generation. Consider adding coder.extrinsic(‘iscellstr’) at the top of the function to bypass code generation.

cvx_begin:
Function ‘iscellstr’ is not supported for code generation. Consider adding coder.extrinsic(‘iscellstr’) at the top of the function to bypass code generation.

cvx_begin:
Cannot load ‘cvxprob’ because code generation does not support classes and enumerations in @-directories.

Note: The same code works fine if i run the m file outside simulink and i added coder.extrinsic(‘iscellstr’) in both cvx_begin and my embedded matlab function but nothing change.

Thanks for help

I’m sorry to say that we don’t support any of MATLAB’s code generation facilities. I’m pleased to hear that it’s working for you with the workaround, but I cannot promise you will not run into any problems otherwise.

Hi,

Did you find any solution for the same? i.e to use the cvx m-file in a matlab function in simulink?

Hi,

Does CVX support code generation to use in Matlab function in Simulink? I have tried and got many errors.

Since the optimization is working fine in usual matlab m-file environment. Is there any way to integrate the code to run with a simulink project? I am trying to use it for real-time optimization.

Thanks for any valuable inputs.

I actually used CVX in Simulink without any problem.
Best Regards,

Can you give us any details of your configuration, as well as what, exactly, you did? Thanks.

it has been used for LMI systems. and also, i had to use it on Simulink.
The .m codes which are not supported on Simulink, must have use with interruption method. So i paused my simulation to solve the problem, as well.

Hi Mark - one workable approach in terms of implementing CVX in a Simulink model is writing a .m-function that performs your CVX optimisation routine and calling it via the “Interpreted Matlab Function” block. The baseline Matlab function block will not work as Simulink attempts to compile this at runtime, whereas the Interpreted Matlab Function is simply a call directly to the Matlab environment.
I can send over a simple Simulink demonstration of this if desired.

It does come with the limitation that any model using CVX in this way can’t be used for code generation, and the Interpreted Matlab Function is a slow and very limited block in general - not every problem that can be solved by CVX will be practicable as an Interpreted Function call. These issues can probably be circumvented by importing code from CVXGEN, but I don’t have access to CVXGEN yet so I haven’t been able to test that hypothesis.

Edit: Never mind, access to CVXGEN has just ticked into my mailbox this morning - might be able to test if the proposed import workaround works sometime next week.