フィルターのクリア

(Container)Map with array keys

4 ビュー (過去 30 日間)
Bananach
Bananach 2016 年 4 月 19 日
回答済み: Titus Edelhofer 2016 年 4 月 19 日
I need a Map whose keys are arrays of integers. MATLAB's Containers.Map does not allow array keys. The implementation with Java's HashMap below also does not work.
jm=java.util.HashMap();
a=[1 1];
jm.put(a,1)
jm.containsKey(a)
I thought that an ad-hoc solution, for fixed array length 2, would be to convert the array into a scalar double (in a reversible way). If there is no other way, could anyone help me doing this?

採用された回答

Titus Edelhofer
Titus Edelhofer 2016 年 4 月 19 日
Hi,
no, there is no "nice" way of doing this. Using a scalar should work fine though:
a = [42 23];
% assume that your indices fit into [0..65535] (example)
key = a(1)*65536 + a(2);
m = containers.Map({key}, {'Bananach'});
% access works
m(key)
% and it's reversible
aFromKey = [floor(key/65536), rem(key, 65536)]
Titus

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by