フィルターのクリア

Counting occurrence of keys and values for Containers.Map in another Containers.Map

1 回表示 (過去 30 日間)
How it is possible to count occurrence of keys and values of Containers.Map A in B?
A = containers.Map({1026,1033,1038,1042},...
{[605.914,48.521],[490.6086 23.7932],[257.558,67.625],[439.090,225.924]});
B = containers.Map({1025,1026,1028,1029,1031,1033,1035,1037,1038},...
{[397.494,168.066],[605.914,48.521],[295.712,176.770],[226.249,209.288],...
[52.573,278.126],[490.6086 23.7932],[50.747,213.198],[38.992,4.417],[257.558,67.625]});
Thank you!!

採用された回答

J. Alex Lee
J. Alex Lee 2020 年 8 月 18 日
Just considering the keys, you can use ismember (though I'm not sure why there's a limitation that cells must be cell arrays of character vectors, and can't be numbers..)
[mask] = ismember(cell2mat(B.keys),cell2mat(A.keys))
cnt = sum(mask)
[mask] = ismember(B.keys,A.keys)
If you need to check if values are the same, you can iterate through the matched keys and use isequal()
  2 件のコメント
Ravindra
Ravindra 2020 年 8 月 18 日
Thank you Lee!!
The first two line works. The following command gives error :
[mask] = ismember(B.keys,A.keys)
Error using cell/ismember (line 34)
Input A of class cell and input B of class cell must be cell
arrays of character vectors, unless one is a character
vector.
I tried another way as well....
C = cell2mat(A.keys)
idx = find(cell2mat(B.keys)== C(1))
idx = find(cell2mat(B.keys)== C(2))
idx = find(cell2mat(B.keys)== C(4))
Thank you again!!
J. Alex Lee
J. Alex Lee 2020 年 8 月 19 日
Yes, sorry should have clarified the last line doesn't work, but seems like a silly limitation by TMW to me. Glad it helps!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by