Using the output of one run of a function as the input of another iteration of that function

3 ビュー (過去 30 日間)
David
David 2022 年 9 月 21 日
回答済み: Matt J 2022 年 9 月 21 日
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

回答 (1 件)

Matt J
Matt J 2022 年 9 月 21 日
for i = 1:Counter
List = ReduceArray(List);
end

カテゴリ

Find more on Loops and Conditional Statements in Help Center and File Exchange

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by