recurSum - %recursive vectors as well out = 0; %terminating...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function out = recurSum(vec) %Given a 1xN array of scalars (a vector), write a function recurSum that %recursively sums the elements of the input array. Your function should %then return this sum. An empty vector ([]) has a sum of 0. %usage: out = recurSum(vec) if isempty(vec) %condition to check if the original vector is empty and all of the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %recursive vectors as well out = 0; %terminating condition; if the vector is empty, simply adds 0 to the %sum else out = vec(1) + recurSum(vec(2:end)); %finds the sum of the recursive function end end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online