Reference no: EM132158914
Use Matlab
Write a function that accepts a variable number of input values and returns the sorted values as an array. The function will be called, for example, like this: b = msort(2,1,4,3) and will return a vector b=[1 2 3 4]
The function should have the following features:
a) Help text, including H1 (first line)
b) The function should sort in ascending order
c) Optionally include a string parameter ‘d' or ‘D' to change the sort order to descending. It should be placed as the last argument to the function, i.e., b=msort(2,1,4,3,'d') returns [4 3 2 1].
d) Have an optional second return argument that includes the number of swaps made during the sort process. If no sorting is done, the number of swaps will be zero. The function is then called as [b,n] = msort(2,1,4,3); here b is assigned the sorted value as above, and n is the number of swaps that occurred during the sorting process.
e)Should work for only a single input argument, i.e., msort(3) returns 3, rather than generating an error.
f) Issue an error if anything other than a number or ‘d' or ‘D' is sent as an argument.