How can I iterate over the keys and elements in a containers.Map?
Show older comments
D = containers.Map('air',1)
for k = keys(D)
D(k)
end
Error using containers.Map/subsref
Specified key type does not match the type expected for this container.
Why does the above cause an error?
Accepted Answer
More Answers (2)
Qixiang Zou
on 11 Aug 2017
D = containers.Map('air',1)
for k = keys(D)
D(k{1}})
end
This should work. Iterator of cell returns element wrapped in a cell. So, add a stupid {1} can save your code.
Alternatively, using strings:
D = containers.Map('air',1);
for k = string(D.keys)
D(k)
end
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!