0% found this document useful (0 votes)
6 views1 page

For Loops in MATLAB and Python

The document compares 'for' loops in MATLAB and Python, illustrating three types: looping with an index, looping through values only, and looping with both index and value. It provides code examples for each type in both programming languages. The examples highlight the syntactical differences between MATLAB and Python for similar looping operations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

For Loops in MATLAB and Python

The document compares 'for' loops in MATLAB and Python, illustrating three types: looping with an index, looping through values only, and looping with both index and value. It provides code examples for each type in both programming languages. The examples highlight the syntactical differences between MATLAB and Python for similar looping operations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

For Loops: MATLAB vs Python

1. Loop with Index

MATLAB
-------------
for i = 1:length(v)
val = v(i);
disp(val)
end
Python
-------------
for i in range(len(v)):
val = v[i]
print(val)

2. Loop through Values Only

MATLAB
-------------
for val = v
disp(val)
end
Python
-------------
for val in v:
print(val)

3. Loop with Index and Value

MATLAB
-------------
for i = 1:length(v)
val = v(i);
disp(i)
disp(val)
end
Python
-------------
for i, val in enumerate(v):
print(i, val)

You might also like