How do I call java code from a Matlab program

后端 未结 1 1456
遇见更好的自我
遇见更好的自我 2021-01-20 23:39

I would like to calling my own Java program from Matlab.

This is my java program:

public class TestArgu{
    public static void main(String[] args){
             


        
相关标签:
1条回答
  • 2021-01-21 00:09

    First, delete the main function from your class. Then add the line

    package mypackage.release;
    

    before your class definition. Then compile it using the command

    javac -verbose -cp /home/javaclasses -d /home/javaclasses /home/javasource/TestArgu.java
    

    In matlab type

    javaaddpath('/home/javaclasses');
    clear java;
    import mypackage.release.*;
    test=TestArgu;
    test.addNumber(6);
    test.ansChk();
    

    Remember that everytime you make changes and compile the java class, you must call clear java in matlab before the changes are available. This also has the unfortunate side effect of clearing all the variables in your workspace so make sure you don't have anything important to save before calling it.

    0 讨论(0)
提交回复
热议问题