I try to run MATLAB code in Java with MATLAB Builder JA to get the JAR file. test.m
works fine, but not the test2.m
that depends on test.m
.
I need the dependency for my project, how to set it up?
test.m
function [out1] = test(n)
out1 = magic(n);
test2.m
function [a] = test2()
a = test();
After building and packaging with Builder JA and run it in Eclipse.
package testJava;
import test.*;
import com.mathworks.toolbox.javabuilder.*;
public class Test {
public static void main(String[] args){
testclass a = null;
Object[] result = null;
try {
a = new testclass();
result = a.test2(1,2);
System.out.println(result[0]);
} catch (MWException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
test2
is not working but test
is working. How do I make test2 work?
One problem is that test2
doesn't actually take any input arguments, but test
requires one.
Try re-writing test2
as
function a = test2(in)
a = test(in);
Also, you should call test2
in you code with only a single input.