MATLAB浏览java属性,在matlab中使用java

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...

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

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.

I tried:

x = Disjoint_Set();

also

x = connected_components_labeling.Disjoint_Set();

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!

解决方案

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...

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:

C:\work\Student.java

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());

}

}

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() )

I get:

Hello unknown

s =

Student@8d6877

ans =

me

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值