Recursion function in matlab

2 Ansichten (letzte 30 Tage)
Noa  Yelin
Noa Yelin am 19 Okt. 2020
Kommentiert: Rik am 20 Okt. 2020
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 Kommentare
Rik
Rik am 19 Okt. 2020
Bearbeitet: Rik am 19 Okt. 2020
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 am 19 Okt. 2020
i want to know how to write a recursive function.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 19 Okt. 2020
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 Kommentare
Noa  Yelin
Noa Yelin am 19 Okt. 2020
thank you!
Rik
Rik am 20 Okt. 2020
If my answer helped, please consider marking it as accepted answer. If not, feel free to comment with your remaining issue.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by