开发者

Fast associative arrays or maps in Matlab

I need to build a fast one-to-one mapping between two large arrays of integers in Matlab. The mapping should take as input an element from a pre-defined array, e.g.:

in_range    = [-200   2  56   45 ... ];

and map it, by its index in the previous array, to the corresponding element开发者_StackOverflow社区 from another pre-defined array, e.g.:

out_range   = [-10000 0  97   600 ... ];

For example, in the case above, my_map(-200) should output -10000, and my_map(45) should output 600.

I need a solution that

  1. Can map very large arrays (~100K elements) relatively efficiently.
  2. Scales well with the bounds of in_range and out_range (i.e. their min and max values)

So far, I have solved this problem using Matlab's external interface to Java with Java's HashMaps, but I was wondering if there was a Matlab-native alternative.

Thanks!


The latest versions of Matlab have hashes. I'm using 2007b and they aren't available, so I use structs whenever I need a hash. Just convert the integers to valid field names with genvarname.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜