create a matlab function that sorts an input vector x from h

create a matlab function that sorts an input vector x from highest to lowest using only if, for and while statements and scaler mathmatics. you may not use any matlab commands other than \"size\". it should have a an output of sorted x and an input of x

Solution

% Test1
>> p = [21 35 3 14 99 101];
x2 = MySort(x, \'descending\')
x2 = 10 5 5 3 2 1

========================

function output = Sortfull(inputelement,method) // creating a methos \'sortfull\' passing 2 arguments
for x = 1:length(inputelement) // condition, checking the length of the element
if(length(inputelement) <= 1)
output=inputelement;
elseif(length(inputelement)>1)
while (length(inputelement)> 1)
if(method(x)==str(\'ascending\')) // for sorting in \'ascendinf ordr, attached for reference.
output=(min(inputelement):max(input));
elseif(method(x)==str(\'descending\')) // soritng done in descending order
output=(max(inputelement):min(input));
elseif(method(x)==str(\'\'))
output=(min(inputelement):max(input));
end
end   
end
end
end

// In the above program, have not used \'sort\' mehtod or other main matlab fucntions, have used loops and only the normal agrregate functions \'min\', \'max\'.

Please verify

create a matlab function that sorts an input vector x from highest to lowest using only if, for and while statements and scaler mathmatics. you may not use any

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site