Why Do I Get an Error When Returning Multiple Values from a Python Package Compiled Using MATLAB R2024b?
1 view (last 30 days)
Show older comments
MathWorks Support Team
on 20 Mar 2025
Answered: MathWorks Support Team
on 21 Mar 2025
I am using a MATLAB function LA_Env_reset within a Python script, which is supposed to return four values: state_1, state_2, state_3, and state_4. I have successfully compiled the MATLAB function into a Python package using MATLAB Compiler SDK and performed initial tests. However, when I attempt to call the function with:
s1, s2, s3, s4 = la_env.LA_Env_reset(la_env_obj, seed, snrdb)
I encounter the following error
TypeError: cannot unpack non-iterable float object
It seems that only one value is being returned instead of four. How can I resolve this issue to retrieve all four expected values?
Accepted Answer
MathWorks Support Team
on 20 Mar 2025
The default behavior of the MATLAB-Python integration is to expect a single output argument from the function call. To retrieve multiple output values, you need to explicitly specify the number of expected outputs using the nargout parameter in your function call.
To resolve the issue, modify your function call to include nargout=4 like this:
s1, s2, s3, s4 = la_env.LA_Env_reset(la_env_obj, seed, snrdb, nargout=4)
0 Comments
More Answers (0)
See Also
Categories
Find more on Python Package Integration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!