在matlab中使用java [英] Use java in matlab

查看:150
本文介绍了在matlab中使用java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用matlab中的java时遇到了问题。我多次阅读MathWork.com的教程,也重新安装了JDK1.6,以便与matlab兼容。但是,在我工作之后,它仍然无效...

I encountered a problem when I tried to use java from matlab. I read through the tutorials from MathWork.com several times, also I re-installed the JDK1.6, in order to be compatible with matlab. However, after my work, it still doesn't work...

以下是classpath.txt中的内容:

Here is the contents in classpath.txt:

    C:\Program Files\MATLAB\R2010a\java\jarext\xstream.jar                                  
    C:\Program Files\MATLAB\R2010a\toolbox\javabuilder\jar\win64   \javabuilder.jar            

    DYNAMIC JAVA PATH

C:\Users\Gao\Desktop\connected_components_labeling

显然,该目录包含在文件中。
connected_component_labeling只是我磁盘上的一个文件夹。我想在connected_components_labeling中使用的类是:Disjoint_Set.class和Node.class在connected_components_labeling文件夹中。

Clearly, the directory is included in the file. The connected_component_labeling is just a folder on my disk. The classes that I want to use in the connected_components_labeling are: Disjoint_Set.class and Node.class are in the connected_components_labeling folder.

我试过:

x =  Disjoint_Set();

x = connected_components_labeling.Disjoint_Set();

它们都不起作用。我从matlab得到的唯一反馈是:

None of them work. The only feedback I got from matlab is:

??? Undefined variable "connected_components_labeling" or class
"connected_components_labeling.Disjoint_Set".

我很沮丧。任何人都可以帮我吗?我很感激。非常感谢!

I'm pretty frustrated. Could anyone help me out? I'd appreciate it. Thanks a ton!

推荐答案

确保使用MATLAB兼容的JRE / JDK编译java文件。据我所知,MATLAB与Java 7无法正常工作,所以暂时坚持使用Java 6 ...

Make sure that you are compiling the java files using a JRE/JDK that MATLAB is compatible with. As far as I can tell, MATLAB does not work properly with Java 7, so stick with Java 6 for the moment...

有几个环境变量可以影响MATLAB。在我的情况下,我有:

There are a couple of environment variables that affect MATLAB. In my case I have:

JAVA_HOME = C:\Program Files\Java\jdk1.6.0_32
MATLAB_JAVA = C:\Program Files\Java\jre6
PATH = ...;C:\Program Files\Java\jdk1.6.0_32\bin

这是我刚做的一个简单测试:

Here is a simple test I just did:

public class Student {
    private String name;
    public Student(String str) {
        name = str;
    }
    public void setName(String str) {
        name = str;
    }
    public String getName() {
        return name;
    }

    public static void main(String args[]) {
        Student s = new Student("amro");
        s.setName("unknown");
        System.out.println("Hello " + s.getName());
    }
}

我编译: javac学生.java (输出放在同一目录 c:\work\Student.class )。现在我从MATLAB测试它:

I compile: javac Student.java (the output is placed in the same directory c:\work\Student.class). Now I test it from MATLAB:

javaaddpath('C:\work')

javaMethod('main','Student','')

s = Student('me')
char( s.getName() )

我得到:

Hello unknown

s =
Student@8d6877

ans =
me

这篇关于在matlab中使用java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆