Recursion happens when a function calls itself, which is something you are not doing.
The first step when creating a recursive function is to identify when the recursion stops. This is done by thinking about how will the function get smaller as you go. In this case, I think we can loop through each value by calling the function with one lessdata point. This means the function ends when the size of the input is less than 3, since we could no longer apply your algorithm.
Another important thing is we need to save what the index of the variable under consideration is so we need to pass the value of c into each new function. So I make the test1 function take c as an input as well and just say that if the function is called without c we set it to 2 to start the recursion.
Then we have your test but we always do it to the second element in the input array. Then we call our function again, increasing c by 1 and removing the first element of data.
Lastly we concatenate the results of the recursion to the results of the function and go back up.
c = 2;
x = ; y = ;
if input(1)>input(2) && input(2)<input(3)
x = c;
y = input(2);
[xRecur, yRecur] = test1(input(2:end),c+1);
x = [x xRecur];
y = [y yRecur];