フィルターのクリア

Problems in running for loop on keys on container maps

6 ビュー (過去 30 日間)
Tsz Tsun
Tsz Tsun 2022 年 8 月 19 日
コメント済み: Tsz Tsun 2022 年 8 月 19 日
Hi all, I am very new to matlab and I have some problems in using container map. I have a ketSet with grid index 1,1 1,2 1,3 and I would like to run a for loop on that to do some dot product. My question is in the for loop p = 1:2, how can I cast the index into the numerical key of the map?
keySet = {'1,1', '1,2', '1,3'};
%use cell array
valueSet = {[2 3], [3 4], [9,6]};
M = containers.Map(keySet,valueSet);
for p=1:2
dot(M('1,p'),M('1,p+1'))
end
Error using indexing
The specified key is not present in this container.

採用された回答

Bruno Luong
Bruno Luong 2022 年 8 月 19 日
keySet = {'1,1', '1,2', '1,3'};
%use cell array
valueSet = {[2 3], [3 4], [9,6]};
M = containers.Map(keySet,valueSet);
for p=1:2
dot(M(sprintf('1,%d',p)),M(sprintf('1,%d',p+1)))
end
ans = 18
ans = 51

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by