Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- close all;
- timer0=(now-datenum(1970,1,1))*86400;
- rng('shuffle');
- %% Data generation
- lower = -10000;
- upper = 10000;
- dataSize = 100000;
- x = 1:dataSize;
- data=zeros(1,dataSize);
- for i=1:dataSize
- data(i)=lower+((upper-lower)*rand());
- if mod(i,10000)==0
- fprintf('Generating random numbers\n');
- end
- end
- fprintf('\nData set generated!\n\n');
- dataUnsorted = data;
- timer1=(now-datenum(1970,1,1))*86400;
- timer2=(now-datenum(1970,1,1))*86400;
- %% Sorting
- for i=1:1:dataSize
- if mod(i,round(dataSize/20))==0
- fprintf('Sorting... Elapsed time: %.3f\n',(now-datenum(1970,1,1))*86400-timer1);
- timer1=(now-datenum(1970,1,1))*86400;
- end
- max=data(i);
- j=i;
- for j = i:dataSize
- if (data(j)>max)
- max=data(j);
- index=j;
- end
- end
- tmp=data(i);
- data(index)=tmp;
- data(i)=max;
- end
- %%
- figure;
- subplot(2,1,1);
- bar(x,dataUnsorted,'r');
- xlim([1 dataSize]);
- ylim([lower upper]);
- title('Unsorted values');
- grid on;
- subplot(2,1,2);
- bar(x,data,'g');
- xlim([1 dataSize]);
- ylim([lower upper]);
- title('Sorted values');
- grid on;
- %%
- fprintf('\nSorting complete!\n');
- fprintf('Total sorting time: %.4f\n',(now-datenum(1970,1,1))*86400-timer2);
- fprintf('Total run time : %.4f\n',(now-datenum(1970,1,1))*86400-timer0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement