for i in range(n): in matlab

In matlab, you can use the for loop in the following way to achieve the functionality of for i in range(n) in Python:

main.m
for i = 1:n
    % Body of the loop
end
39 chars
4 lines

In this loop, i starts from 1 and goes up to n (inclusive) in steps of 1. You can replace n with any integer value based on your requirement.

Here is an example loop that prints the values of i from 1 to n:

main.m
n = 5;
for i = 1:n
    disp(i);
end
36 chars
5 lines

Output:

main.m
1
2
3
4
5
10 chars
6 lines

related categories

gistlibby LogSnag