This preview shows page 1. Sign up to view the full content.
Unformatted text preview: %the recursive vectors are empty out = ; %terminating condition; sets the output equal to an empty vector if vec %is an empty vector else out = sort(vec); %sorts the given vector end end vec = slowlySort(vec); %calls the slowSort function to put the vector into ascending order if isempty(vec) %terminating condition out = ; %output elseif length(vec)==2 %accounts for if the length of the vector is 2 numbers out = sum(vec)./2; %finds the average of the two numbers elseif length(vec)==1 %accounts for it the length of the vector is 1 number out = vec; %assigns the output to that value else out = recurMedian(vec(2:end-1)); %calls the original function and eliminates the first and last elements %each time the function is called (moving toward terminating condition end e end...
View Full Document
- Spring '08