using structure as a value for containers.Map
3 ビュー (過去 30 日間)
古いコメントを表示
I am trying to add a structure as a value for container.Map, for example I'm trying to add segments strcuture to cont container.
Code:
Properties
segments = struct('signal', {}, 'time', {})
cont = containers.Map('KeyType','int32','ValueType','any');
end
fucntion:
if length(map) == 0
i = 2;
this.cont(1) = this.segments;
else
this.cont(i) = this.segments;
i = i+1;
end
Is this even possible, It adds fine, but when i try to retrieve the values.
cont.values(1)
I am getting:
Error using containers.Map/values
Parameter must be 'cell'.
0 件のコメント
回答 (1 件)
Guillaume
2016 年 7 月 27 日
The valueSet returned by the values function is a cell array of whatever is stored in the map. Therefore,
cont.values{1}
would retrieve the 1st item stored in the map. If you're storing structures, then values{1} is a structure.
Important: using values is not the normal way to retrieve elements stored in the map. In particular, there is no guarantee that values{1} correspond to a key value of 1. To retrieve the value corresponding to a key value of 1:
valforkey1 = cont(1)
The two operations are vastly different. cont.values returns a cell array whose elements are in the same order as cont.keys, but there is no guarantee that cont.keys{1} has value 1.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!