Matlab sorting code help: sort(x) which sort the elements of vector x in an asce
ID: 640700 • Letter: M
Question
Matlab sorting code help:
sort(x) which sort the elements of vector x in an ascending order.
Hints:
Sort (using bubble sort method) 1) Set x=some arbitrary row vector of order N, and set counter=0 2) Repeat the following procedure for N-1 times (outside loop): Repeat the following commands for N-1 times (inside loop): counter=counter+1 if x(counter)>x(counter+1) then swap them
So I think I have the code pretty much to where it needs to be, I'm just having trouble getting the answer to display correctly.
%% Sort
clear;clc;
x=input('Input your vector for X=[?] ');
N=length(x);
while (N>0)
counter=0;
for i=1:1:N-1
if (x(i)>x(i+1))
temp=x(i);
x(i)=x(i+1);
x(i+1)=temp;
counter=i;
end
end
N=counter;
disp(N);
end
Explanation / Answer
Hi, I can do a high quality guaranteed A+ solution for you. Trust me once and I will help you forever. Just follow the instruction here: http://programmingtutor3.tk