Alternative to makima interpolation method in python packaged matlab code.

7 visualizzazioni (ultimi 30 giorni)
Hi,
Im using a matlab simulink model in my python package that uses the makima interpolation method in a look-up table.
I replaced it by another method (cubic) because the code generation did not work. Is there a way/workaround to use this method in my model without using another Toolbox like Matlab-Coder?
I could write a function that interpolates instead of a look up table and then exclude this function from code generation.
But then the documentation says, that the matlab engine is being used instead. When I use the coder e.g. coder.extrinsic('foo') to exclude the interpolation will this then work in a compiled and packaged simulink model? Does "matlab engine" include matlab runtime?
Because runtime is the only thing avaible for the distributed python package.
Also I'd appreciate a method that works without the matlab coder because I only need it for one single application.
Thanks in advance for your comments.

Risposte (1)

Sai Pavan
Sai Pavan il 23 Gen 2024
Hello Christopher,
I understand that you are looking for alternate ways to use a Simulink model that uses 'makima' interpolation in a python package. Using MATLAB's `makima` interpolation method directly within a Simulink model that needs to be compiled for code generation can be challenging because not all MATLAB functions are supported for code generation. If `makima` is not supported, and you want to avoid using MATLAB Coder or another Toolbox, you have a few options:
  • Custom Interpolation Function: You can write a custom interpolation function that mimics the behavior of `makima` and is compatible with code generation. This function would need to be written in a subset of MATLAB functions that is supported for code generation. You can then integrate this function into your Simulink model directly, without needing to call an extrinsic function.
  • Use Extrinsic Functions: If you choose to use an extrinsic function with `coder.extrinsic`, the function call will be dispatched to MATLAB at runtime, which means the MATLAB Engine will be used. This approach is not suitable for standalone applications because it requires a live MATLAB session to execute the extrinsic function. The MATLAB Engine is not the same as the MATLAB Runtime. The MATLAB Runtime allows you to run compiled MATLAB applications without a MATLAB license, but it does not support executing arbitrary MATLAB code via extrinsic calls. Therefore, this approach would not work with only the MATLAB Runtime available.
  • Precomputed Lookup Table: Another workaround is to precompute the lookup table in MATLAB using the `makima` method and then import this table into your Simulink model as a static dataset. You can then use the cubic or another supported interpolation method within Simulink to interpolate values from this precomputed table. This approach avoids the need for real-time interpolation using `makima` and should be compatible with code generation.
  • External Code Integration: You could implement the `makima` interpolation in a programming language that is compatible with your target environment (such as C/C++ for embedded systems) and then integrate this code with your Simulink model using the Legacy Code Tool or S-Function approach. This way, the interpolation method becomes part of the generated code without relying on MATLAB function calls at runtime.
If you need to generate standalone code that does not require MATLAB at runtime, you should avoid using extrinsic functions that call back into MATLAB. Instead, you can either implement a custom interpolation function in MATLAB that is compatible with code generation, use a precomputed lookup table, or integrate external code written in a language that supports the desired interpolation method. If you are not familiar with writing code for code generation in MATLAB, the precomputed lookup table may be the simplest and most straightforward solution.
Hope it helps!

Categorie

Scopri di più su MATLAB Compiler in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by