Get content of cell array when looping over it
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!