Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matlab problem Write a function that accepts a variable number input values and returns the sorted values as an array. The function will be called

Matlab problem image text in transcribed
Write a function that accepts a variable number input values and returns the sorted values as an array. The function will be called for example like this. B = msort(2, 4, 1, 5) and will return a vector b = [1 2 3 4] (either row or column vector is OK) The function should have the following features: Help text including HI (first line) The function should sort in ascending order, i.e., from lowest to highest. 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| Have an Optional second return argument that include a 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. Should work for only a single input argument, i.e., msort(3) return 3, rather than generating an error. Issue an error if anything other than a number or 'd'or D is sent as an argument. Useful functions: lower() - returns lower case of a string or character lower("D") 'd' isonumeric() - returns TRUE (1) if arguments a number, else returns FALSE (0) ischar() - returns TRUE(1) if argument is a character or string else returns FALSE(0) Run your function on the following lists and include both the final sort value and the number of swaps: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 both ascending and descending Your ID number using each digit as a separate argument (9 total) i.e., 106-321-987would be called as msort(1, 0, 6, 3, 2, 1, 9, 8, 7) Call the function with ten random numbers. You can either make them up, compute them ahead d time and copy them in, or generate them on the fly as follows: msort(rand(), rand(), rand(), rand(), rand(), rand(), rand(), rand(), rand())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions