- Import the module:Instead of importing "testApp", import the module generated by the Library Compiler. It likely has a different name (check the generated files).
- Use the initialize function:The Library Compiler typically provides an "initialize" function to create an instance of the converted class. Use this function to create an object and then call its methods.
How to convert matlab to python?
151 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I use library compiler to convert matlab code to python, my code listed. The conversion is successful but I can't use the code in python.
Matlab Code:
classdef testApp
properties
a1 = 0;
a2 = 0;
end
methods
function obj = start(obj,x1,x2)
obj.a1 = x1;
obj.a2 = x2;
end
end
end
Python Code:
import matlab
import testApp
aaa = testApp.initialize()
a = aaa.start(1,2)
vv = 1
Error:
SystemError: Error in MATLAB Compiler SDK for Python. Details: An error occurred during evaluation of the function start. Details: Function start not found in Python package.
0 comentarios
Respuestas (1)
surya venu
el 24 de Mayo de 2024
Editada: surya venu
el 20 de Jun. de 2024
Hi,
The issue lies in how you're trying to use the converted Python code. Here's the problem and the fix:
Problem:
The Library Compiler creates a Python package, not a directly usable class. You're trying to call the "start" method on the "testApp" class directly, which isn't the intended approach.
Fix:
Here's the corrected Python code:
import <module_name> # Replace with the actual module name
# Create an instance of the class
aaa = <module_name>.initialize()
# Call the start method on the instance
a = aaa.start(1, 2)
vv = 1
For more information, check out: https://www.mathworks.com/help/compiler_sdk/gs/create-a-python-application-with-matlab-code.html
Hope it helps.
2 comentarios
surya venu
el 20 de Jun. de 2024
Editada: surya venu
el 20 de Jun. de 2024
Check out this link: https://www.mathworks.com/help/compiler_sdk/gs/create-a-python-application-with-matlab-code.html
In the Install and Run MATLAB Generated Python Application section if you see,
import <Module_Name>
# Import the matlab module only after you have imported
# MATLAB Compiler SDK generated Python modules.
import matlab
In your case it's done vise versa.
Let me know, after changing if it works.
Ver también
Categorías
Más información sobre Python Package Integration en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!