
Making two 3D vectors the same length
조회 수: 3 (최근 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));
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Assembly에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!