Help to preallocate a data structure
2 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
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.
0 Comments
See Also
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!