Borrar filtros
Borrar filtros

Making two 3D vectors the same length

18 visualizaciones (últimos 30 días)
alexandra ligeti
alexandra ligeti el 9 de Jun. de 2021
Comentada: alexandra ligeti el 9 de Jun. de 2021
Hi,
I have two vectors, vector_static and vector_dynamic which both contain x, y ,z coordinates, however vector static is 421X3 and vector dynamic is 489x3 in length. How do I pad vector static with zeros at the end so that both vectors are the same dimension? I need them to be the same dimension to carry out the dot product on them, so to calculate the angle between. The data is also only changing in the y and z planes so I would only need to dot these components, however, any help regarding changing the dimesions of the matrix would be greatly appreciated.
Thanks in advance
The code I have so far is:
%%Points on pendulum
%Point 1 S =Source Static
point_1_S = [SourceSx, SourceSy, SourceSz];
%Point 1 D =Source Dynamic
point_1_D = [SourceDx, SourceDy, SourceDz];
%Point 2 S = Fusion static
point_2_S = [FusionSx, FusionSy, FusionSz];
%Point 2 D = Fusion dynamic
point_2_D = [FusionDx, FusionDy, FusionDz];
% Creating a vector between the fusion and source sensors
Vector_static = point_2_S - point_1_S;
Vector_dynamic = point_2_D - point_1_D;
%Calculate the angle between vectors
A = cat(4,Vector_static); % Combine the three components in the 4th dimension
B = cat(4,Vector_dynamic); % Ditto
C = cross(A,B,4); % Take the cross products there.
ang_SD = atan2(sqrt(dot(C,C,4)),dot(A,B,4));

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 9 de Jun. de 2021
Editada: Scott MacKenzie el 9 de Jun. de 2021
Given that your question is...
How do I pad vector static with zeros at the end so that both vectors are the same dimension?
then here is a simply way to achieve this:
% test matrices, sized as per question
vStatic = rand(421,3);
vDynamic = rand(489,3);
% pad with zeros so both are same size
vStatic(end:size(vDynamic,1),:) = 0;
Result:
  1 comentario
alexandra ligeti
alexandra ligeti el 9 de Jun. de 2021
Thank you so much. This works so well. Appreciate the help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by