Matlab compiler - matlabruntimeforpython : "Dot indexing is not supported for variables of this type" when calling sim()

13 views (last 30 days)
I am evaluating Matlab Compiler SDK. One of the things I did is to try to call a Simulink model from Python using matlabruntimeforpython. I am having trouble getting the output out of the simulation.
I asked a similar question yesterday while trying to achieve the same thing with matlab engine.
Using Matlab 2020b and Python 3.6. I wrote this function:
function [power] = RunSimpleModelSim(time, voltage, current)
modelname = 'simpleModel';
stopTime = 1;
simstep = 0.0001;
load_system(modelname);
set_param(modelname, 'StopTime', num2str(stopTime));
set_param(modelname, 'FixedStep', num2str(simstep));
input_voltage = timeseries(voltage, time);
input_current = timeseries(current, time);
assignin('base', 'input_voltage', input_voltage);
assignin('base', 'input_current', input_current);
out = sim(modelname);
power = out.power;
plot(power);
end
Then with Matlab Compiler SDK, I published this function as a shared library n the Python Package format.
I am able to load my module, initialize it and call the function with parameters, but it fails at the "sim" function
import myModule
import matlab
handle = myModule.initialize()
time = matlab.double([0,1])
voltage = matlab.double([20,25])
current = matlab.double([10,15])
handle.RunSimpleModelSim(time, voltage, current)
This is what I get:
Dot indexing is not supported for variables of this type.
Error in Simulink.standalone_sim
Error in RunSimpleModelSim (line 19)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\MATLAB\R2020b\toolbox\compiler_sdk\pysdk_py\matlab_pysdk\runtime\deployablefunc.py", line 80, in __call__
nlhsWasSpecified, stdoutObj, stderrObj).result()
File "C:\Program Files\MATLAB\R2020b\toolbox\compiler_sdk\pysdk_py\matlab_pysdk\runtime\futureresult.py", line 135, in result
raise e
File "C:\Program Files\MATLAB\R2020b\toolbox\compiler_sdk\pysdk_py\matlab_pysdk\runtime\futureresult.py", line 123, in result
raise e
File "C:\Program Files\MATLAB\R2020b\toolbox\compiler_sdk\pysdk_py\matlab_pysdk\runtime\futureresult.py", line 113, in result
self._nlhs, out=self._out, err=self._err)
matlab_pysdk.runtime.MatlabRuntimeError: An error occurred when evaluating the result from a function. Details:
File C:\Program Files\MATLAB\R2020b\mcr\toolbox\simulink_standalone\shared\+Simulink\standalone_sim.p, line 0, in standalone_sim
File C:\Users\Pier-yves.lessard\AppData\Local\Temp\Pier-Yves.Lessard\mcrCache9.9\RunSim6\RunSimpleMod\RunSimpleModelSim.m, line 19, in RunSimpleModelSim
Dot indexing is not supported for variables of this type.
Here's my questions:
  1. How can I fix this?
  2. Is the model generated in rapid accelerator when published with Matlab Compiler SDK?
  3. I noticed I can't set more than one param at the time with set_param, which I can do when running standard Matlab code. Am I right to understand that the Matlab Runtime SDK is a lightweight version of the real matlab engine; therefore I should expect some restriction/changes in the usage of it (v.s. standard engine)?
Regards

Accepted Answer

Joel Van Sickel
Joel Van Sickel on 22 Dec 2021
The sim command is not supported by the matlab compiler. You need the Simulink compiler for that OR you need to use embedded coder to generate a DLL that can be called by any piece of software. The Simulink compiler is the much easier way. I apologize that the error message was not clear about that.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by