Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab equivalent of Python enumerate

Tags:

python

matlab

In Python, we have a convenient function enumerate:

for i,item in enumerate(foo_list):
    do something

Is there a Matlab equivalent to enumerate?

For now, what I can think of is something like the following (Matlab code):

i=1;
for foo=foo_list
    ....
    i=i+1;
end
like image 420
wdg Avatar asked Aug 24 '14 06:08

wdg


1 Answers

As far as I know, there is no equivalent of enumerate in Matlab. The most common way to do this is:

for i = 1:length(foo_list)
    item = foo_list(i);
    % do stuff with i, item
end
like image 117
Bas Swinckels Avatar answered Sep 20 '22 13:09

Bas Swinckels