How to make the length/dimension of 6 different 3D vectors the same?

조회 수: 5 (최근 30일)
alexandra ligeti 2021년 6월 11일
댓글: alexandra ligeti 2021년 6월 11일
I have 6 different vectors, each containing their own independant x, y, z coordinates. I would like to calculate the cross product and so to be able to do that, I need the vectors be the the same dimension. The dimensions of the vectors are as seen in the image below. The longest vector is 852, so I would like the other vectors to be 852 entries in length with the end values being padded with the value of zero to make up the end entires to ensure the length recahes 852. Is there an easy way to do this?
I have tried a for loop but it is not filling the end values of the shorter vectors with zeros and I cant seem to get it to work for more than one vector.
So just to reiterate, I am looking for a method to get all vector dimenstions the same, and where the vector lengths are not equal in length I would like the shorter length vectors to contain zero value entires padded to the end to make up the remaining entires ensuring the length of all vectors is the same as that of the longest vector.
Thank you for your help.

댓글을 달려면 로그인하십시오.

채택된 답변

Joseph Cheng 2021년 6월 11일
probably the easiest way is to fill a zero array created to be the same max size then populate the indexes with the values:
var1 = rand(100,3);
var2 = rand(50,3);
pmax = max([size(var1,1) size(var2,1)])
pmax = 100
Zvar1(1:size(var1),:)=var1;
Zvar2(1:size(var2),:)=var2;
figure,plot(1:pmax,Zvar1,1:pmax,Zvar2,'x')
댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
alexandra ligeti 2021년 6월 11일
Thank you, this is exactly what I needed! Works perfectly.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by