MATLAB to JAVA conversion
18 views (last 30 days)
Show older comments
In our recent project we wanted to use a MATLAB function in JAVA enviroment. Our function takes objects as an input. We use LibraryCompiler to convert MATLAB code to JAVA. So we create a JAVA library. However, when we try to employ the function in JAVA the function is almost unusable.
The problem is that the function does not accept objects as input. When we convert the function to JAVA the input type is determined as object but the object type is not specified so function does not recognize the object. So we have to create another function to create a object. For example, In the example below we want to convert my_func to JAVA. But when we convert the function the function does not recognize the object. We want to create an object in JAVA and give it directly as a input to our function is there any way we can do this?
***************************************************************************
classdef example
properties
key=5
query=5
end
end
function [outputArg1] = my_func(example)
outputArg1 = example.key+example.query;
end
obj1=example;
my_func(obj1)
***************************************************************************
0 Comments
Answers (1)
Akash
on 29 Aug 2023
Hi Ferit CAN,
I understand that you are facing difficulties when trying to use a MATLAB function in your Java application, specifically when passing objects as input.
Please note that MATLAB objects are not directly compatible with Java applications. To overcome this issue, you will need to convert the MATLAB object into a format that can be recognized and utilized by your Java application. The MATLAB documentation provides detailed guidance on how to pass data to Java methods, which can help you achieve the desired functionality. You can find more information in the Passing Data to Java Methods section of the documentation: https://in.mathworks.com/help/matlab/matlab_external/passing-data-to-java-methods.html
By following the guidelines provided in the documentation, you will be able to create a Java object and pass it as input to your MATLAB function successfully.
0 Comments
See Also
Categories
Find more on Call Java from MATLAB 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!