{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

recurMedian

# recurMedian - %the recursive vectors are empty out...

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

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) function out = slowlySort(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
This is the end of the preview. Sign up to access the rest of the document.

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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern