I need help preallocating an array of position vectors

1 view (last 30 days)
Creating an array that stores the position vectors of circles detected in each frame of a video, how would i go about preallocating posvec?
posvec = [];
for frame_no = 1 : stack_size(4)
framecropped = frame_stack(:,:,:,frame_no);
imshow(framecropped);
[pos,rad] = imfindcircles(framecropped,[20 100]);
viscircles(pos,rad);
drawnow
posvec = [posvec; pos];
end

Accepted Answer

Stephen23
Stephen23 on 21 May 2021
Use a cell array:
tmpout = cell(1,stack_size(4))
for frame_no = 1:stack_size(4)
..
tmpout{frame_no} = pos;
end
matrix = vertcat(tmpout{:}); % optional
  3 Comments
Alexander Watkins
Alexander Watkins on 21 May 2021
Ah I just forgot to change the vector name from posvec to the vertcat of posvec, thank you.

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!