How to loop on vector values and have indices too

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
funyhony
Messages
7
Reaction score
0
i want to loop on K vector values
K = [3 5 7 9 11]

and have with me inside the loop the index of the current vector value

if i made
for K = [3 5 7 9 11]
disp(K)
end

i'll not have the index of K values

i mean when K=9 i want to know that I'm in index 4

how to make that??
 
Physics news on Phys.org
What language are you looking to do this in? If this is MATLAB, your output would actually display the index value (K) with every iteration of the loop. Given how quickly this would execute, you'll probably just see 3, 5, 7, 9, 11 printed on successive lines.