Is there a matlab equivalent of the “for in” loop in python?
For instance in python, I can iterate through items of a list using the following code:
for c_value in C_VALUES:
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In MATLAB,
foriterates over the columns of a matrix. Pretty much the same as your example, ifC_VALUESwere a row.is the MATLAB syntax.
valwill take on the values ofrow_vecas it iterates. The syntax you will often see (but isn’t strictly necessary) isHere,
1:length(values)creates a row vector[1 2 3 ...], andiican be used to index intovalues.(Note:
iis another common choice, but as soon as you useiin this type of context where it is assigned a value, you don’t get to use it in the imaginary number sense anymore).