In MATLAB, to get a range of numbers that start from a certain number and goes down in one step, you can use the colon operator :
within square brackets [] along with the decrement operator --
.
For example, to generate a range of numbers from 10 to 1 in decrement of 1, you can write:
main.m42 chars2 lines
This will create an array range
containing the values [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
.
Alternatively, you can also use the flip
function, which reverses the order of an array:
main.m20 chars2 lines
The flip
function takes an array as input and outputs a new array with the elements in reverse order. In this case, the input is the range of numbers from 1 to 10, and output is the same numbers in reverse order.
Hope this helps!
gistlibby LogSnag