Dont not use MATLAB built-in functions! Write a MATLAB function that sorts the e
ID: 2960934 • Letter: D
Question
Dont not use MATLAB built-in functions!
Write a MATLAB function that sorts the elements of a numeric array in increasing order. Your function should accept two arguments: input_array (the array to sort) and len (the length of the array to sort). Your function is expected to return one output value, sorted_array, which is of length len. Warning: You will get zero credit if you simply call a MATLAB built-in function that does this. Sort the following array using the function you wrote in Part (a): a = [83, 48, 39, 88, 63, 71, 1, 20, 36, 16]Explanation / Answer
open the editor and paste this. save this script as arraysort
function sorted_array = arraysort(input_array,len)
for i=1:len
for j=1:len-i
if(input_array(j)>input_array(j+1))
temp=input_array(j+1);
input_array(j+1)=input_array(j);
input_array(j)=temp;
end
end
end
sorted_array=input_array;
now type the following in the command window
a=[83 48 39 88 63 71 1 20 36 16];
b=arraysort(a,10)
you get b as your sorted array
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.