- 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?
142 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
surya venu
am 24 Mai 2024
Bearbeitet: surya venu
am 20 Jun. 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 Kommentare
surya venu
am 20 Jun. 2024
Bearbeitet: surya venu
am 20 Jun. 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.
Siehe auch
Kategorien
Mehr zu Python Package Integration finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!