How to change a for loop to a recursive function?
Show older comments
Hi!
I'm new to Matlab but I'm trying my best to improve as quickly as possible. I'm trying to make a function just by using recursion, which is really new to me. I've got this
res=[0,res]
for N=(length(res):-1:2)
if res(N)>9
res(N)=res(N)-10;
res(N-1)=res(N-1)+1;
end
end
which in theory will make array 'res' into single digit cells. The value of each original cell never surpasses 18.
This is not for any school project or anything marked. This is an enquiry to improve my matlab skills.
Can you help me? What is the best way to transform this into a recursive function?
Thank you in advance,
EKB
Accepted Answer
More Answers (0)
Categories
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!