Storing MATLAB structs in Java objects

后端 未结 3 762
栀梦
栀梦 2020-12-05 21:34

I\'m using Java HashMap in MATLAB

h = java.util.HashMap;

And while strings, arrays and matrices works seemlessly with it

h.         


        
3条回答
  •  醉话见心
    2020-12-05 21:40

    Matlab R2008b and newer have a containers.Map class that provides HashMap-like functionality on native Matlab datatypes, so they'll work with structs, cells, user-defined Matlab objects, and so on.

    % Must initialize with a dummy value to allow numeric keys
    m = containers.Map(0, 0, 'uniformValues',false);
    % Remove dummy entry
    m.remove(0);
    
    m(5) = 'test';
    m(7) = magic(4);
    m(9) = struct('foo',42, 'bar',1:3);
    m(5), m(7), m(9) % get values back out
    

提交回复
热议问题