I have a large Map in matlab and want to traverse all the keys of it. But I can only store a cell for the keys first and traverse the cell, which calls for memory to store all the keys. While in python, the generator/iterator can sequentially give the indexes or entries of list back in loops, which does not cost much memory.
In matlab, I tried for
loop:
% Let MAP is a containers.Map with 10000000 keys.
keys = MAP.keys;
for keyIdx = 1:size(keys,2)
MAP(keys{1,keyIdx});
end
While in python, the for
loop with iterator:
% Let MAP is a dictionary with 10000000 keys.
for key in MAP.iterkeys():
MAP[key]
So, is there generator/iterator like that in python in matlab to save memory when I process the maps?