Question: IN MATLAB Write a function that sorts the input array according to the magnitude of values and returns this sorted array. The sorted array is

IN MATLAB

Write a function that sorts the input array according to the magnitude of values and returns this sorted array.

The sorted array is returned by the function not printed by the function.

For example, when the input is [1 2 3] the result is [1 2 3]

For example, when the input is [1 -2 3] the result is [1 -2 3]

For example, when the input is [-1 2 -3] the result is [-1 2 -3]

For example, when the input is [3 2 -2 2 1] the result is [1 2 -2 2 3]

when two elements have the same magnitude but a different sign, order those elements negative first, then positive.

For example, when the input is [3 2 -2 2 1 -3] the result is [1 -2 -2 2 -3 3]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!