Reputation: 2138
I have a java.util.HashMap object that I want to convert generally into a MatLab datatype, perhaps the new containers.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?
Upvotes: 1
Views: 671
Reputation: 2080
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.
Upvotes: 2