Get content of cell array when looping over it
Show older comments
Lets say I have a map
results = containers.Map;
and I add some things to my map such as
results('a') = struct('hello', 1, 'world', 2);
results('b') = struct('foo', 3, 'bar', 4);
how would I loop through my results map to get the stucts back.
Example that works:
for k = results.keys
key = k{1}; % Since k is a 1x1 cell
results(key)
end
Is there a way to have k "unpack" the cell in the for statement, something like this is what I am looking for
for {k} = results.keys % Does not work, can't unpack a cell like this {k}, has to be k{1}
results(k)
end
any suggestions on how to write this nicely?
my current solution is
for k = results.keys
results(k{1}) %Seems a bit hard to read.
end
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!