Can one dynamically add new keys to a Maps data structure in Matlab?

25 ビュー (過去 30 日間)
Brando Miranda
Brando Miranda 2018 年 3 月 30 日
コメント済み: Muhammad Shaban 2019 年 6 月 7 日
I recently discovered the maps data structure but it seems I can't dynamically assign new keys to it. I am going through some files and don't know the keys beforehand (unless I loops through everything first to get the keys and then again to get the data). Is it possible to not have to loop through things twice and just instead add new keys as I discover them?
[note this is easy to do in python with a dictionary with `dictionary[new_key] = data` ]
  1 件のコメント
Muhammad Shaban
Muhammad Shaban 2019 年 6 月 7 日
Adding a new key-value pair is same as python e.g map_variable(new_key)= data.

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

回答 (1 件)

Steven Lord
Steven Lord 2018 年 3 月 30 日
That should work if you do it as is shown by the last example on the containers.Map documentation page. Can you show the full error message (everything in red) you receive when you try? That may show us why it's not working or suggest a further avenue for investigation.
  7 件のコメント
Steven Lord
Steven Lord 2018 年 3 月 30 日
What does class return when called on the variables noise and all_test_accs on line 19 of collect_flatness_results?
Brando Miranda
Brando Miranda 2018 年 3 月 30 日
編集済み: Brando Miranda 2018 年 3 月 30 日
Steven, I think I solved it, if you put 'any' Maps can hold any type. The variables there are double and the other is an array of doubles. Thanks! :D

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

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by