You can use the find
function along with the diff
function to achieve this. The diff
function will calculate the differences between consecutive values in the input array, and the find
function will return the indices of the values that meet a certain condition (in this case, the condition is that the difference is not equal to 1).
Here is the code:
main.m45 chars3 lines
This will output:
main.m14 chars2 lines
Note that the +1
is added to the end of the find
statement to account for the fact that diff
reduces the size of the array by one.
gistlibby LogSnag