Question: Following is the code used in matlab to sort a vector. n=length(A); for i=1:n for j=1:i if A(j) < A(i) Temp =A(i); A(i)=A(j); A(j)=Temp; end

2- function [ B] = Sort_Array (A): This function will call on

Following is the code used in matlab to sort a vector.

n=length(A);  for i=1:n     for j=1:i        if A(j) < A(i)         Temp =A(i);         A(i)=A(j);         A(j)=Temp;        end     end  enddisp(A)

I'm not sure how to create code such that any array can be sorted without the use of the sorting command. It is required to use the code above, which sorts a vector. This is also done in MATLAB. I appreciate any and all help.

2- function [ B] = Sort_Array (A): This function will call on the sorting function you created in your previous submission to sort a vector from largest to smallest. This function would sort an array column by column, such that in each column the largest number becomes the first row element, and the smallest number moves down to the last row. For example, I had designed function [B] = Select_Sort(A) to sort any vector; I am using this new array sorting function Sort_Array function in my "command window" to get an array 'x' sorted out. >> x=randi ([-1 4],3,4) X = ^ 3 4 -1 4 2 4 3 -1 -1 >> B=Sort_Array (x); >> B B = 4 2 0 2 -1 4 2 4 -1 4 4 4 -1

Step by Step Solution

3.54 Rating (151 Votes )

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!