Help to preallocate a data structure

2 views (last 30 days)
Emil
Emil on 5 Jan 2015
Answered: Image Analyst on 5 Jan 2015
I have a for loop in this form
for i = 1:20
vec(i).q = vector1{i};
vec(i).w = vector2{i};
end
vector1 and vector2 are cell arrays of vectors. How do i preallocate the structure "vec", and what kind of structure is it?

Answers (1)

Image Analyst
Image Analyst on 5 Jan 2015
Try this:
vector = cell(20,1);
vec = struct('q', vector, 'w', vector)
% Check, by assigning some vector and printing it out
vec(13).q = [1,2,3,4] % Assign an array
vec(13).q % Print to command window.

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!