开发者

Can MatLab understand Java int datatype?

I have a java.util.HashMap object that I want to convert generally into a MatLab datatype, perhaps the new container开发者_如何转开发s.Map type.

Ideally I could do:

it = javaHashMapObj.keySet.iterator;
while it.hasNext
    jkey = it.next;
    someMatlabObj(jkey) = javaHashMapObj.get(jkey);
end

Among other potential problems (please point out, resolve if they jump out at you!), there is the issue that if the Java HashMap is keyed with integers, it.next will nevertheless return MatLab double objects, which will then not work as keys into the HashMap with javaHashMapObj.get.

Can someone suggest a way to resolve this? Extend the Java object to give me the MatLab int32 for the keys?


MATLAB will convert a regularly entered number (which is a double) to a Java primitive int, but if you want an Integer Object, you have to explicitly box it yourself:

javaHashMapobj.get(java.lang.Integer(key));

See http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f6425.html for a table of how data types are converted from MATLAB to Java.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜