cat u are using an unsupported browser Please see our syste CHALLENGE5.11.1: Row
ID: 3753230 • Letter: C
Question
cat u are using an unsupported browser Please see our syste CHALLENGE5.11.1: Row sort This tool is provided by a third party. Though your activity may be recorded, a page refresh may be needed to fill the banner Row sort Write a function called CustomSort that takes a 2D array InMat with random integers between-100 and 100 (inclusive), and produces an nx m array called outMat, which consists of sorted values in inMat such that the lowest value in inMat is the (1,1) position in outMat. CustomSort orders the remaining elements trom left to right on the first row until the last column, progressing with each row. Hint: The internal functions sort and reshape should be used. Restrictions: Loops should not be used. Ex: 8 19 8 11 17 6 12 16 12 16 2 19 11 16 2 3 [outMat] Customsort( inMat ) produces 12 12 16 16 16 17 19 19 Reset MATLAB Your FunctionExplanation / Answer
Matlab function:--
function [outMat]=CustomSort(inMat) % function that takes inMat matrix of any size
[r c]=size(inMat); % find size of matrix inMat
A = reshape(inMat,[1,r*c]); % reshape the matrix as row matrix
B = sort(A); % sort the row matrix
C = reshape(B,[r,c]); % reshape the sorted matrix as inMat dim
outMat=C'; % because reshape done by column wise take transpose for row wise sort
end
output:--
>> inMat=[
8 19 8 11
17 6 12 16
12 16 2 19
11 16 2 3];
>> [outMat]=CustomSort(inMat)
outMat =
2 2 3 6
8 8 11 11
12 12 16 16
16 17 19 19
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.