Get content of cell array when looping over it
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!