Write a function that accepts a variable number of input

Assignment Help Computer Engineering
Reference no: EM132171567

By using 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] (either row or column vector is OK) The function should have the following features:

- Help text, including H1 (first line)

- The function should sort in ascending order, i.e., from lowest to highest.

- Optionally include a string parameter ‘d' or ‘D' to change the sort order to descending, i.e., highest to lowest. 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 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.

- Should work for only a single input argument, i.e., msort(3) returns 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() isnumeric() ischar()

- returns lower case of a string or character: lower(‘D')='d'

- returns TRUE (1) if argument is a number, else returns FALSE (0)

- 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:

a) 1, 2,3,4,5,6,7,8,9,10 both ascending and descending

b) Your ID number, using each digit as a separate argument (9 total), i.e., 106-321-

987 would be called as msort(1,0,6,3,2,1,9,8,7)

c) Call the function with ten random numbers. You can either make them up,

compute them ahead of time and copy them in, or generate them on the fly as follows: msort(rand(),rand(),rand(),rand(),rand(),rand(),rand(),rand(),rand(),rand())

Reference no: EM132171567

Questions Cloud

Generate a table of conversions from celsius to rankine : Generate a table of conversions from Celsius to Rankine. Allow the user to enter the starting temperature and the increment between lines.
Write a function that returns the depth of the input a : Write a function celldepth(A, unused) that returns the depth of the input A (the second input unused should be part of your function definition.
Analyse the key elements of the marketing function : Critically analyse and evaluate the key elements of the marketing function and how they interrelate with other functional units - Marketing in KFC
What is the importance of change management : What is the importance of change management? Describe the role of a change manager?
Write a function that accepts a variable number of input : Write a function that accepts a variable number of input values and returns the sorted values as an array.
What are the seven objectives of the ondcp : What are the seven objectives of the ONDCP? What is the National Southwest Border Counternarcotics Strategy? What are its objectives?
Company cola product that is targeted to male consumers : New 10-calorie version of the company's cola product that is targeted to male consumers.
Write one function that performs the same activity : Write one function that performs the same activity as the built in Matlab functions rot90, fliplr, and flipud.
Discuss implications of your style for current position : Describe the style that you choose. Discuss the implications of your style for your current position.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Describe one application relevant for ig based energy system

IGs need dc-ac, ac-dc, and ac-ac converters. Describe one application, relevant for IG-based energy system, for each of those power conversions.

  Briefly describe the concept of queues

Briefly describe the concept of queues.

  Describe three types of multicomputer configurations

How does a supercomputer differ from a mainframe computer? Describe three types of multicomputer configurations. What are their comparative advantages?

  Create a powerpoint presentation on the topic

Pick a current article of your choice that fits within the scope of the topic (topic is: email in the internet or DNS) for the week or the course in general.

  Discuss some of the information technology needs of health

write 400-600 words that respond to the following questions with your thoughts ideas and comments. be substantive and

  Do research and write a paper on structured analysis

Nassi-Shneiderman structure charts (yes, that's Ben Shneiderman, before he became famous for his work in HCI).

  Write a java application that uses the math class

Write a Java application that uses the Math class to determine the answers for the square root of 37.

  Malware paper - how effective it is at evading detection

Malware Paper, Note three kinds of malware that are active threats today. Note the following for each type: How common it is, A brief explanation of how it works and How effective it is at evading detection

  What your states laws are regarding cyber stalking

Using the Web or other resources, find out what your states laws are regarding cyber stalking. Write a brief essay describing those laws and what they mean.

  Design a web page to provide a metric conversion guide

Design a web page to provide a metric conversion guide for college students.

  While a typical database is created the structure

When a typical database is created the structure is created before the data is actually loaded into the database. What problems exist when someone wants to add or delete from existing structure? What methods can you see for accomplishing the restr..

  Express what makes one algorithm better than another

A non-technical friend has asked whether some algorithms are better than others. express what makes one algorithm better than another.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd