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數組中,請哪位大牛可以幫忙解決一下呀?真心的是感謝一下呀!
總結
以上是生活随笔為你收集整理的matlab程序转java_用面向对象的方法将一段JAVA代码转化为matlab的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 没有bug队——加贝——Python 练
- 下一篇: matlab人脸追踪,求大神帮助我这个菜