Question: Create 1 D and 2 D arrays using the commands:Write local function SortD 1 array to sort 1 D arrays. The function must have input

Create 1D and 2D arrays using the commands:Write local function SortD1array to sort 1D arrays. The function must have input arguments arr and sortOrder and output argument arrSorted. This function must not use a Matlab sorting function. The sorting algorithm should be based on repeatedly finding the maximum element of the input array, removing this element from the input array, and adding this element to a new array. This needs to be repeated until the input array becomes empty. Specifically, implement the following steps:
Initialize an empty array arrSorted with [] assignment
Construct a while-loop that runs while array arr is not empty (use built-in Matlab function isempty).
On every loop iteration:
find the first maximum value of arr and its index indMax using a built-in Matlab function
add this value to arrSorted by concatenation
eliminate this element from arr by assigning empty value [] to the element with index indMax. This reduces the number of elements in arr by 1
The while loop will exit once all elements are removed from arr and added to arrSorted. After finishing the loop, arrSorted will be arranged in descending order. If sortOrder equals "up"(ascending order), flip the array arrSorted
Using the function SortD1array, sort the 1D array aD1 in ascending order returning array aD1Sorted.
Determine the number or rows and columns in the 2D array aD2. Using a for-loop and the SortD1array function, sort all rows of aD2 individually in descending order assigning the result to array aD2SortedRows.
Flatten the array aD2 and use the SortD1array function to sort all values of aD2 in ascending order. Then, reshape the sorted 1D array into the original aD2 dimensions. Assign the result to array aD2SortedAll
Print the original arrays and the sorted arrays with comments.
Organize your script in Input, Calculations, and Output sections. Include cleaning commands; provide comments; suppress intermediate output. Use only those Matlab methods that were described in class.
Create 1 D and 2 D arrays using the

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 Programming Questions!