matlab程序转java_用面向对象的方法将一段JAVA代码转化为matlab

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

public class Variable {

/*list of variables this variable is connected to. */ Vector neighbors;

/* id of this variable */

public int varID;

/* id of agent this variable belongs to. */

public int agentID;

/** The domain of possible values for this variable. */

Value[] domain;

/** Size of the domain */

int domainSize; public Variable(int agentID, int varID, int domain_s) {

this.agentID = agentID;

this.varID = varID;

domainSize = domain_s;

/* set the domain of the variable to be int values between [0,]. */

domain = new NominalValue[domainSize];

for(int i=1;i

domain[i] = new NominalValue(i);

}

neighbors = new Vector();

} public void addNeighbor(Variable v){ neighbors.addElement(v);

}

public boolean isNeighbor(Variable v){

for(int i=0;i

Variable vv = (Variable) neighbors.elementAt(i);

if(v.equalVar(vv))

return true;

}

return false;

} }

下面是我写的matlab类,主要问题在于addElement()总报错

classdef Variable

%VARIABLE Summary of this class goes here

% Detailed explanation goes here

properties

neighbors ;

varID ;

agentID ;

domain ;

domainSize ;

end

methods

%Class Constructor

function obj = Variable(agentID , varID , domain_s)

import java.util.*;

import problem.*;

obj.agentID=agentID;

obj.varID = varID ;

obj.domainSize = domain_s ;

% set the domain of the variable to be int values between [0,].

obj.domain = problem.NominalValue(obj.domainSize);

for i = 1:obj.domainSize

obj.domain(i)=problem.NominalValue(i);

end

obj.neighbors = Vector();

end

%Class Constructor end

end

method

function addNeighbor(obj,v)

obj.neighbors.addElement(v);

end function bool_isNeighbor = isNeighbor(obj,v)

for i = 0 : neighboors.size()

vv = Variable(obj.neighbors.elementAt(i));

if v.equalVar(vv)

bool_isNeighbor = true ;

return ;

end

end

bool_isNeighbor = false ;

end

end

我现在的问题主要在addElement(v) 这部分,不能把一个对象加入到neighbors数组中,请哪位大牛可以帮忙解决一下呀?真心的是感谢一下呀!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值