Recursion function in matlab

1 次查看(过去 30 天)
Noa  Yelin
Noa Yelin 2020-10-19
评论: Rik 2020-10-20
Hey
How do I write a function that get a matrix as an argument and returns the sum of all the members in it recursively?
Thanks you
  2 个评论
Rik
Rik 2020-10-19
编辑:Rik 2020-10-19
You can find guidelines for posting homework on this forum here. If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks).
Is your question how to write a recursive function at all? Or do you want someone else to do your complete homework assignment for you?
Noa  Yelin
Noa Yelin 2020-10-19
i want to know how to write a recursive function.

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2020-10-19
function n=I_call_myself(n)
disp(n)
if n>0
n=I_call_myself(n-1);
else
disp('n has reached 0')
end
end
  2 个评论
Rik
Rik 2020-10-20
If my answer helped, please consider marking it as accepted answer. If not, feel free to comment with your remaining issue.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by