How to extract a structure from a nested structure

4 ビュー (過去 30 日間)
Blue
Blue 2019 年 8 月 5 日
コメント済み: Adam Danz 2019 年 8 月 5 日
Hello,
I have a nested structure that look like this:
% Create table
Name = {'A', 'A', 'A', 'B', 'B', 'B', 'C', 'C', 'C'}.';
Month = [1, 2, 3, 1, 2, 3, 1, 2, 3].';
Lat = [49, 50, 51, 52, 53, 54, 49, 50, 51].';
Lon = [-99, -100, -101, -102, -103, -104, -99, -100, -101,].';
A = [0.1, 0.2 , 0.3, 1.1, 0.9, 1.0, 0.1, 0.2 , 0.3,].';
T = table(Name, Month, Lat, Lon, A);
% Convert to structure
t2 = varfun(@(x){x(:)'},T,'GroupingVariables','Name');
TinStrr = t2(:,[1,3:end]);
TinStrr.Properties.VariableNames = T.Properties.VariableNames;
S_out = table2struct(TinStrr);
How can I extract the first structure (A) as a 1x1 structure ?
Thank you

採用された回答

Adam Danz
Adam Danz 2019 年 8 月 5 日
編集済み: Adam Danz 2019 年 8 月 5 日
A = S_out(1);
...but if possible, rather than extracting it and using "A", keep the structure array together and just use "S_out(1)". This approach keeps the data more organized and the code more readable.
  2 件のコメント
Blue
Blue 2019 年 8 月 5 日
Ah. That was simpler than I thought. Thank you.
Adam Danz
Adam Danz 2019 年 8 月 5 日
Glad I could help! Consider keeping the structure array together, though. Structure arrays get really sad when you separate their members.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by