2

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.