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
Get step-by-step solutions from verified subject matter experts
