How to rank and sort angles of a matrix

The Question:
Let the vector x be the 1st column of A.
Find the cosine of the angle between x and each column in A. (column 1 better have a cosine of 1!)
Rank the columns by their cosines, and list the column numbers of the 8 highest ranked columns, together with their cosines.
What I have done so far:
A=rand(50,900);
A=vertcat(A,A,A,A);
[p,d,q]=svds(A,30);
B =p*d*transpose(q);
x=A(:,1);
for i=1:900
Z= dot(x,A(:,i))/(norm(x)*norm(A(:,i)))
end
The issue I am running into is, I am not sure how to combine all the 900 elements I am creating into one matrix. As of now, they are just rewriting each other, so I only have one element with this equation. I am very new to matlab, so any help would be very appreciated.

 Accepted Answer

Make the left hand side Z(i) instead of Z

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!