function idx=HW13(X,Y) % Input: X is n x p and Y is n x m. Output the indices found by the OLS % algorithm. [n,p]=size(X); [n,m]=size(Y); %Normalize X and Y for i=1:p-1 %Compute cos^2(theta) between the p columns of X and m columns of Y %(Should be a p x m matrix for the first time through). C= %Get the best row norm of C. You might find Matlab's max function useful % (You should look up the help file for it) %Put the winning column as xwin and delete the corresponding column from % the matrix X. xwin= %Deflate the remaining columns of X. You may use a loop if you are more %comfortable with that: [nn,pp]=size(X); for j=1:pp X(:,j)=X(:,j)- %Subtract the appropriate projection. end %Re-normalize the columns of X: end