%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The University of Texas at Dallas % ECON 7309 - Econometrics II % Professor Donggyu Sul, Ph.D. % % Cesar Zamudio % Ph.D. Student, Marketing % Fall 2010 % % Assignment 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear;clc; %Download X and Y variables from the class homepage. %Throughout I assume Column 1 is Variable X, and Column 2 is Variable Y. %data=load('Assignment 1 - Data X and Y.csv'); data=load('datayx.csv'); X=data(:,1); Y=data(:,2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %QA. Sort X from smallest to largest. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %We will use the straight insertion algorithm. n=size(X,1); Xsorted=X; subplot(2,1,1) for j=1:1:n target=Xsorted(j,1); i=j-1; while (i>0 && Xsorted(i,1)>target) Xsorted(i+1,1)=Xsorted(i); i=i-1; end Xsorted(i+1)=target; pause(.005) plot(Xsorted,'bo-') title('Sorting using straight insertion algorithm - X') end disp('Sorted elements of X (smallest to largest)') Xsorted %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %QB. Sort Y from largest to smallest. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %We could simply "flip" a vector sorted from smallest to largest. For the %purposes of the assignment, however, we will modify the algorithm above to %sort in the opposite way. This can be done by reversing the inequality in %the while loop. subplot(2,1,2) n=size(Y,1); Ysorted=Y; for j=1:1:n target=Ysorted(j,1); i=j-1; while (i>0 && Ysorted(i,1)