i'm trying to extract elements from a structure and can do what i need to using
X = vertcat(S(1).Norm_X,S(2).Norm_X,S(3).Norm_X);
however i would like to use a for loop in case the size of the structure changes.
for i = 1:numel(data)
X= vertcat(S(i).Norm_X)
end
However this method overwrites X each time it goes through the loop so rather than having a 3x100 double i have a 1x100 double which was last through the loop.

 採用された回答

Stephen23
Stephen23 2017 年 10 月 31 日
編集済み: Stephen23 2017 年 10 月 31 日

1 投票

You can use a comma-separated list, no loop is required:
X = vertcat(S.Norm_X)
See this answer for a detailed explanation:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2017 年 10 月 31 日

編集済み:

2017 年 10 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by