简体   繁体   中英

Matlab: I want to emulate a hashmap of 3D points to a list of 3D points. What is the best way?

basically, I want to do

(.1,.2,.3) => ( (.1,.2,.2),(.1,.2,.1) )
(.2,.1,.1) => ( (.1,.1,.1) )

how would I implement this in matlab?

In java it would be a Hashmap<3DPoint, ArrayList<3DPoint>>

There are two ways to go about this:

You can create a nKeys -by-2 cell array, such as

{[.1,.2,.3], [.1,.2,.2;.1,.2,.1];...
[.2,.1,.1], [.1,.1,.1]}

While a cell array can be convenient to manipulate using eg CELLFUN , it does not provide fast lookup.

If you have a more recent version of Matlab, you can use the MAP -class. Here, numerical keys can only be scalars, but using NUM2STR , you can convert the 3D vectors into 1-by-N strings. Make sure you write '0.1' instead of '.1', though, to avoid confusion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM