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

  What is the length of a wimax connection id

What is the length of a WiMAX connection ID? What are three examples of last mile connections? What is the maximum speed of WiMAX in the 10-66 GHz bands?

  Draw a diagram of the given error-control scenario

Draw a diagram of this error-control scenario, and show the response(s) that Station B will send. Now assume that five seconds after Station B responds.

  State the union and intersection of the 2 sets and the

part i demonstrate demorgans laws using a venn diagram. define 2 sets and a universal set within which the 2 sets

  Create the method contract for getcoursebycourseid method

Create the method contract for the GetCourseByCourseID() method of the CourseList class. Explain your work and the decisions you made to arrive at your proposed solution.

  Implement the playexpert mode of the game

Whether or not you have managed to implement the playExpert mode of the game. If you do not manage to implement it you should carry on with the rest of the questions in novice mode.

  Implement entry insertion and removal in a skip list

Implement entry insertion and removal in a skip list using a strictly top-down, scan-forward approach, without ever using the above or prev methods.

  Write a method that returns the height of an AVL tree

Write a method that returns the height of an AVL tree by tracing only one path to a leaf, not by investigating all the nodes in the tree.

  We have witnessed sharp increases in quality and quantity

competition has since the 90s led to wider gaps between industry leaders and laggards. there are more winner-take-all

  Calculate the key and compare the value

Calculate the key and compare the value to _KEY . If the two match, the user (most likely) entered the correct password, otherwise he loses one chance.

  Define vulnerability and risk in terms of security

Define vulnerability, threat and risk in terms of security. Why do you think sometimes they are used synonymously?

  Why do you think the given method is not used any more

Since a tape can easily be simulated on disk (as a file), why do you think this method is not used any more?

  How might the file be compromised in the given case

UNIX treats file directories in the same fashion as files; that is, both are defined by the same type of data structure, called an inode.

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