How do I concatenate a single field from a multi-dimensional struct?
Show older comments
I have a 1xN struct where a specific field is always an Mx1 cell array of strings, and I wish to concatenate all of these cell arrays without using a for loop. Any idea of how I may do this? Here's an example to illustrate what I mean:
var_info =
1×8 struct array with fields:
name
vars
path
size(var_info(1).vars)
ans =
51 1
size(var_info(6).vars)
ans =
8 1
I can achieve this now using for loops (see below) But I figured there must be some more elegant method of doing so that doesn't use as much memory. (Note: The unique function is included so I can get rid of duplicate strings as I go.)
entire_list = {};
for i = 1:length(var_info)
entire_list = [entire_list; var_info(i).vars];
entire_list = unique(entire_list);
end
Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on Structures 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!