How do I create multiple column vectors from one big column vector?

조회 수: 6 (최근 30일)
Chad
Chad 2020년 3월 24일
댓글: Adam Danz 2020년 3월 25일
I have two column vectors, objx and objy, both of which contain 20,160 floats. I need to dice it up every 48 iterations to create voronoi figures. There will be 420 voronoi diagrams. How do I go about creating smaller vectors each of which containg 48 floats each to create these voronoi diagrams?
  댓글 수: 5
Chad
Chad 2020년 3월 24일
The column vectors are both 20160x1, there are 20160 rows and just 1 column, in each vector. Each row only has one numeric element. Its just 20160 numbers stacked on eachother.
Adam Danz
Adam Danz 2020년 3월 24일
That's clear. The comma in 20,160 threw me off. There's no need to use a comma unless the number of digits is very large.

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 24일
편집: Ameer Hamza 2020년 3월 24일
Try this
X = reshape(objx, 48, 420); % X is 48*420
Y = reshape(objy, 48, 420); % Y is 48*420
% loop will run 420 times
for i=1:size(X,2)
x = X(:,i); % x is 48*1
y = Y(:,i); % y is 48*1
voronoi(x,y);
% save the voronoi diagram
end
  댓글 수: 11
Ameer Hamza
Ameer Hamza 2020년 3월 25일
@Adam, thanks for suggesting the improvements. I am not sure whether it will make any difference for reshaping function that input is a row or column vector, as long as it has just one dimension. For higher-order matrices, we need to be careful about the arrangement of elements.
Adam Danz
Adam Danz 2020년 3월 25일
That's true; a col or row vector will result in the same reshape. My mind may have still been on the possibility of cell arrays converted to matrices.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Voronoi Diagram에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by