'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
David Hill 2021 年 10 月 28 日

0 投票

z=[];
for k=1:217
s=sprintf('DATA.Segment%d.data',k);
z=[z;eval(s)];
end

2 件のコメント

Matthew Mitchell
Matthew Mitchell 2021 年 10 月 28 日
great! Thanks a million
Akira Agata
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 ExchangeCreating and Concatenating Matrices についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 10 月 28 日

編集済み:

2021 年 11 月 1 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by