Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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!

like image 619
Amelio Vazquez-Reina Avatar asked Oct 13 '22 17:10

Amelio Vazquez-Reina


1 Answers

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.

like image 67
Rich C Avatar answered Nov 16 '22 12:11

Rich C