loop through negative decimals in matlab

To loop through negative decimals in MATLAB, you can use a for loop and specify the start, end, and step size of the loop using negative decimal values. Here's an example:

main.m
for i = -0.1:-0.1:-1
    disp(i);
end
38 chars
4 lines

In this example, the loop starts at -0.1, decrements by -0.1, and stops when i reaches -1. The disp function is used to display each value of i in the Command Window.

Output:

main.m
   -0.1000
   -0.2000
   -0.3000
   -0.4000
   -0.5000
   -0.6000
   -0.7000
   -0.8000
   -0.9000
   -1.0000
110 chars
11 lines

Alternatively, you can also use a while loop to iterate through negative decimals:

main.m
i = -0.1;
while i >= -1
    disp(i);
    i = i - 0.1;
end
58 chars
6 lines

In this example, the loop starts at -0.1 and continues as long as i is greater than or equal to -1. The disp function is used to display each value of i in the Command Window. The loop also updates the value of i by subtracting 0.1 in each iteration.

Output:

main.m
   -0.1000
   -0.2000
   -0.3000
   -0.4000
   -0.5000
   -0.6000
   -0.7000
   -0.8000
   -0.9000
   -1.0000
110 chars
11 lines

gistlibby LogSnag