image thumbnail

Array sorting

by

 

28 Sep 2011 (Updated )

Program for Sorting of Array in Matlab

[out]=Array_sort()
function [out]=Array_sort()
%%
% Code for the user input;
clc
a=input('Enter the size of matrix');
matrix=1:a;
disp('Enter the nos');
for i=1:a
    matrix(i)=input('');
end
%%
% Code for sorting the Array;
for i=1:a
    for j=i+1:a
        if(matrix(i)>matrix(j))
            var=matrix(i);
            matrix(i)=matrix(j);
            matrix(j)=var;
        end
    end
    out=matrix;
end

        

Contact us