Map between two cell arrays
古いコメントを表示
Hi,
I want to map two cell arrays.
Following the Containers.Map documentation it is possible : "Keys, specified as a numeric array, cell array of character vectors, or string array."
But if I try :
V = num2cell(rand(5,3));
K = num2cell([1 2; 3 4; 5 6; 1 2; 3 4]);
Then :
M = containers.Map(K,V);
I get the error :
Error using containers.Map
Unsupported key specified. See documentation for valid key types.
However K and V are both 5 x 1 cell arrays. What am I missing here ?
Thanks for help.
Nicolas
Edit : I would like each row of V matching with its key row in K.
7 件のコメント
Nicolas Douillet
2019 年 12 月 11 日
Stephen23
2019 年 12 月 11 日
"However K and V are both 5 x 1 cell arrays."
Yes... they are cell arrays of numeric arrays.
"What am I missing here ?"
Do you have cell arrays of character vectors (as the documentation requires)? (hint: no)
Nicolas Douillet
2019 年 12 月 11 日
編集済み: Nicolas Douillet
2019 年 12 月 11 日
"Do you see what I am trying to do ?"
Not really, as you did not explain anything about what you expect to get, and your code has unexplained "features" (e.g. cell arrays of numerics, non-unique keys).
Lets imagine that you get this to work: what value would you expect the key 1 to map to?
Nicolas Douillet
2019 年 12 月 11 日
"You are right, there may be several values for a given key. "
In that case, if you use a key with multiple values do you expect MATLAB to return:
- one value (e.g. the last one defined using that key), or
- all of the values that have that key?
Please state your preference.
Nicolas Douillet
2019 年 12 月 11 日
編集済み: Nicolas Douillet
2019 年 12 月 11 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!