Making two 3D vectors the same length
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
alexandra ligeti
le 9 Juin 2021
Commenté : alexandra ligeti
le 9 Juin 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));
0 commentaires
Réponse acceptée
Scott MacKenzie
le 9 Juin 2021
Modifié(e) : Scott MacKenzie
le 9 Juin 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:
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Sparse Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!