Most "MATLABesque" way to create mutable nested key value structure
古いコメントを表示
Just started learning MATLAB and have a background in Python. It seems that containers.Map() is the MATLAB structure most analagous to a python dictionary object but from what I can tell it isn't really optimized for modifying nested structures. For example:
>>>test = containers.Map('food', containers.Map())
>>>test('food')('hotdog')='yummy'
Returns
Error: ()-indexing must appear last in an index expression.
While the same syntax for a non-nested structure works fine:
>>>test = containers.Map('food','hotdog')
>>>test('drinks')='beer'
I realize that MATLAB can read/write JSON files directly but that isn't a very elegant solution. What is the "correct" MATLAB data structure for storing nested key value paired data?
採用された回答
その他の回答 (1 件)
Walter Roberson
2018 年 11 月 30 日
0 投票
fetch the nested item and store it in aa variable. Modify. Store the modified version in the top level container .
MATLAB does not generally permit indexing of the results of computation but has an exception for dot indexing of java. This is not a general exception, but {} indexing has some leeway . For example {} indexing of tables and string objects probably gets closer to computation than static addressing , but the results are indexable .
カテゴリ
ヘルプ センター および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!