Angle between multiple unit vectors contained within a matrix.
Mostrar comentarios más antiguos
Hi all,
This should be pretty simple but it's escaping me.
I have two matrices (a and b) which contain 10 unit vectors. I would like to calculate the angle between the ten pairs. When I try the method below it gives me a single value as the norm function normalises the whole matrix.
Any thoughts would be most welcome.
% Example vectors. They won't be the same when used.
a_single = [0,0,1];
b_single = [1,0,1];
a_norm = a_single./norm(a_single);
b_norm = b_single./norm(b_single);
% Repeat for 10 elements
a = repmat(a_norm, [10,1]);
b = repmat(b_norm, [10,1]);
% Calculate angle between them.
cosOfAngle = max(min(dot(a,b)/(norm(a)*norm(b)),1),-1);
angle = real(acosd(cosOfAngle))
Respuesta aceptada
Más respuestas (1)
Rob Malkin
el 14 de Feb. de 2023
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!