recurMedian - out = vec else end end function out =...

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

View Full Document Right Arrow Icon
function out = recurMedian(vec) %Given a 1xN array of scalars (a vector), write a function recurMedian %that recursively calculates the median of the input array. For a sorted %array with an odd number of elements, the median is defined as the %middle element of the array. For a sorted array with an even number of %elements, the median is defined as the average of the two middle %elements of the array. Your function should return this median. Return %an empty vector if the input is empty. %usage: out = recurMedian(vec) vec = slowSort(vec); if isempty(vec) out = []; elseif length(vecmod(length(vec),2)==0 out = sum(vec)./2; elseif mod(length(vec),2)==1
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: out = vec; else end end function out = slowSort(vec) %Given a 1xN array of scalars (a vector), write a function slowSort %that recursively sorts the vector in ascending order and outputs this %sorted vector. %usage: out = slowSort(vec) if isempty(vec) %initial condition to check and see if the original vector and all of %the recursive vectors are empty out = ; %terminating condition; sets the output equal to an empty vector if vec %is an empty vector else out = [min(vec) slowSort(vec(min(vec)~=vec))]; %concatenates the minimum with the recursive function to continue to %keep increasing the order 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 Tech.

Ask a homework question - tutors are online