How do I concatenate a single field from a multi-dimensional struct?
显示 更早的评论
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.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!