Making two 3D vectors the same length

19 次查看(过去 30 天)
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));

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-6-9
编辑:Scott MacKenzie 2021-6-9
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:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by