How to create a struct from a cell array of fieldnames and a cell array of values?
Show older comments
How can you take a cell array array of fieldnames and a cell array of values, and convert them into a structure without looping?
names = {'f1', 'f2'};
values = {1 2};
structure = struct(???)
Accepted Answer
More Answers (1)
Matt J
on 18 Jan 2013
cell2struct(values,names,2)
2 Comments
Eric Sampson
on 18 Jan 2013
Jan
on 18 Jan 2013
It is not documented but even slightly faster, to omit the 3rd input dimension, when values and names are {nx1} cells.
Categories
Find more on Structures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!