how to count from -1 to 101 in matlab

To count from -1 to 101 in MATLAB, you can use a for loop with an if statement to check if the current value is within the desired range. Here's an example code block that accomplishes this:

main.m
for i = -1:101
    if i >= 0
        disp(i);
    end
end
58 chars
6 lines

Explanation:

  • First, we create a for loop that iterates from -1 to 101 using the syntax for i = -1:101.
  • Inside the loop, we use an if statement to check whether i is greater than or equal to 0. This ensures that we only display values between 0 and 101.
  • If i meets this condition, we display it using the disp() function.

Note that this code block assumes you want to count from -1 to 101, inclusive of 0 and 101. If you want to exclude these values, you can change the loop to for i = 0:100 and the if statement to if i > 0.

gistlibby LogSnag