%% Script file to test our bestdir function: X=[1 -2 1;0 1 2;1 1 1]; %y=[1;7;4]; y=[1 0;7 2;4 4]; used(1)=bestdir(X,y); %Remove that column, and project out that direction from the others: v= %v is the column that we're keeping X(:,used)=[]; %delete that column from X X=X- %Projection (Careful with parentheses!) %Repeat: used(2)=bestdir(X,y) v= X(:,used(2))=[]; X=X-