concatenate vector within nested structures
显示 更早的评论
'DATA' is a 1x1 struct containing 217 fields. Each field is a structure containing a double array labelled 'data'.
I would like to concatenate the 'data' array in each of the 217 fields into one vector.
The structure containing the dat ais attached
any help would be greatly appreciated.
回答(1 个)
David Hill
2021-10-28
z=[];
for k=1:217
s=sprintf('DATA.Segment%d.data',k);
z=[z;eval(s)];
end
2 个评论
Matthew Mitchell
2021-10-28
Akira Agata
2021-11-1
编辑:Akira Agata
2021-11-1
+1
The following way can avoid 'eval' function:
load("lvm2matDATA.mat");
% Extract field names containing "Segment"
list = fieldnames(DATA);
list = list(contains(list,"Segment"));
% Concatenate data
tData = [];
for kk = 1:numel(list)
tData = [tData, DATA.(list{kk}).data];
end
% Arrange it as a table variable
tData = array2table(tData,"VariableNames",list);
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!