Using the output of one run of a function as the input of another iteration of that function
Hi so I’ve a problem where I have made a function that adds neighbouring elements and reduces its size (i.e. 50 elements reduces to 25 after one run of the function). What I want to do is repeat the function until the size of the matrix is 1 so that I can output the final addition. I cannot wrap my head around the loops to use since I want the loop to use the output of the previous iteration as the input for the next iteration i.e. the next run of the same function. For example 50 -> 25 -> 13 -> 7 -> 4 -> 2 -> 1 elements
I was thinking something like this but it just repeats the first step (50 -> 25 -> 13) a load of times
Thank you for your help
for i = 1:Counter
outputv = ReduceArray(List)
inputv = ReduceArray(outputv);
endHi so I’ve a problem where I have made a function that adds neighbouring elements and reduces its size (i.e. 50 elements reduces to 25 after one run of the function). What I want to do is repeat the function until the size of the matrix is 1 so that I can output the final addition. I cannot wrap my head around the loops to use since I want the loop to use the output of the previous iteration as the input for the next iteration i.e. the next run of the same function. For example 50 -> 25 -> 13 -> 7 -> 4 -> 2 -> 1 elements
I was thinking something like this but it just repeats the first step (50 -> 25 -> 13) a load of times
Thank you for your help
for i = 1:Counter
outputv = ReduceArray(List)
inputv = ReduceArray(outputv);
end Hi so I’ve a problem where I have made a function that adds neighbouring elements and reduces its size (i.e. 50 elements reduces to 25 after one run of the function). What I want to do is repeat the function until the size of the matrix is 1 so that I can output the final addition. I cannot wrap my head around the loops to use since I want the loop to use the output of the previous iteration as the input for the next iteration i.e. the next run of the same function. For example 50 -> 25 -> 13 -> 7 -> 4 -> 2 -> 1 elements
I was thinking something like this but it just repeats the first step (50 -> 25 -> 13) a load of times
Thank you for your help
for i = 1:Counter
outputv = ReduceArray(List)
inputv = ReduceArray(outputv);
end loop MATLAB Answers — New Questions