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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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