Unable to Unpack Variables from Python to MATLAB Function in Simulink Model
Hi everyone,
I’m beginner in Matlab and I’m working on a project where I need to replace a scalar control block for an induction motor in Simulink with my own control block written in Python. The Python function calculates three variables that I need to pass back to MATLAB Function block, and convert to vector.
However, I’m running into an issue where MATLAB seems to treat these variables as non-iterable and can’t unpack them properly. Even though my Python function returns a tuple with the three variables, MATLAB can’t seem to process them as intended.
Here’s a summary of the setup:
MATLAB Function:
function Vabc = Run_in_Python(fRef)
Vabc = zeros(3, 1);
coder.extrinsic(‘py.ControllerPython.calc’);
result = cell(py.ControllerPython.calc(fRef));
Vabc = vertcat(result);
end
Error:
Python Error: TypeError: cannot unpack non-iterable int object Error in calc Error in ‘InductionMachineScalar/Control/Scalar controller/MATLAB Function’ (line 6)
Thanks in advance!Hi everyone,
I’m beginner in Matlab and I’m working on a project where I need to replace a scalar control block for an induction motor in Simulink with my own control block written in Python. The Python function calculates three variables that I need to pass back to MATLAB Function block, and convert to vector.
However, I’m running into an issue where MATLAB seems to treat these variables as non-iterable and can’t unpack them properly. Even though my Python function returns a tuple with the three variables, MATLAB can’t seem to process them as intended.
Here’s a summary of the setup:
MATLAB Function:
function Vabc = Run_in_Python(fRef)
Vabc = zeros(3, 1);
coder.extrinsic(‘py.ControllerPython.calc’);
result = cell(py.ControllerPython.calc(fRef));
Vabc = vertcat(result);
end
Error:
Python Error: TypeError: cannot unpack non-iterable int object Error in calc Error in ‘InductionMachineScalar/Control/Scalar controller/MATLAB Function’ (line 6)
Thanks in advance! Hi everyone,
I’m beginner in Matlab and I’m working on a project where I need to replace a scalar control block for an induction motor in Simulink with my own control block written in Python. The Python function calculates three variables that I need to pass back to MATLAB Function block, and convert to vector.
However, I’m running into an issue where MATLAB seems to treat these variables as non-iterable and can’t unpack them properly. Even though my Python function returns a tuple with the three variables, MATLAB can’t seem to process them as intended.
Here’s a summary of the setup:
MATLAB Function:
function Vabc = Run_in_Python(fRef)
Vabc = zeros(3, 1);
coder.extrinsic(‘py.ControllerPython.calc’);
result = cell(py.ControllerPython.calc(fRef));
Vabc = vertcat(result);
end
Error:
Python Error: TypeError: cannot unpack non-iterable int object Error in calc Error in ‘InductionMachineScalar/Control/Scalar controller/MATLAB Function’ (line 6)
Thanks in advance! matlab simulink python integration coder.extrinsic, simulink, python, cell arrays MATLAB Answers — New Questions