Note that there are some explanatory texts on larger screens.

plurals
  1. POStore MATLAB class instance into java.util.HashMap
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/436852/storing-matlab-structs-in-java-objects">Storing MATLAB structs in Java objects</a> </p> </blockquote> <p>I'm currently using <a href="http://www.mathworks.com/help/techdoc/ref/containers_map.html" rel="nofollow noreferrer"><code>containers.Map</code></a> to associate keys and values in MATLAB. However, quick tests show that this class is really slow compared to <code>java.util.HashMap</code>. The documentation does not specify the algorithmic complexity for storage and retrieval, so I'm scared it's not using a hash table, and I really need flat performance (O(1) insertion and retrieval).</p> <p>I've been trying to convert my code using <code>containers.Map</code> to <code>java.util.HashMap</code>, but it doesn't work when I try to insert custom MATLAB class instances into the hash map. For instance, given the following class</p> <pre><code>classdef Bucket &lt; handle % ... application-specific code ... end </code></pre> <p>I can't do this:</p> <pre><code>m = java.util.HashMap(); % association. b = Bucket(); % class instance. k = ...; % some relevant value for association. m.put(k, b); </code></pre> <p>It fails with the error message:</p> <blockquote> <p>??? No method 'put' with matching signature found for class 'java.util.HashMap'.</p> </blockquote> <p>The exact same code works if I replace <code>b</code> with some non-custom class, such as:</p> <pre><code>b = 'foo'; m.put(k, b); </code></pre> <p>How can I store <code>Bucket</code> instances in a <code>java.util.HashMap</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload