How to loop on vector values and have indices too

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
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.