A recursive matrix sum
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Noa Yelin
il 21 Ott 2020
Commentato: Noa Yelin
il 21 Ott 2020
Hey
I wrote a function that gives u the sum of the matrix. I try to write it with rerursive, but it doen't get well. i need an explanation..
this is my code -
function total=ff(l)
total = 0;
for i = 1:numel(l)
total = total+l(i);
end
any help?
2 Commenti
Risposta accettata
Asad (Mehrzad) Khoddam
il 21 Ott 2020
You function is not recursive
function total=ff(l)
lp=l(:);
if numel(l) == 1
total = l(1);
else
total = lp(end) + ff(lp(1:end-1));
end
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!