Loop over variables with just a number in the name different

2 ビュー (過去 30 日間)
Gert Guldentops
Gert Guldentops 2014 年 2 月 4 日
回答済み: Walter Roberson 2014 年 2 月 4 日
Hello, I have a number of vectors: WD.Tair1 WD.Tair2 WD.Tair3 WD.Tair4
I would like to loop over them and each time return me the seventh number in each of them. How can I do this? Be aware that the vetors are not of the same lentgh.
Period = 1;
for Period = 1:4 %loop over all different time periods
T0 = WD.Tair???(7);
end
I hope you get it. Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 2 月 4 日
In your case, use dynamic field names.
for Period = 1 : 4
fn = sprintf('Tair%d', Period);
T0 = WD.(fn);
....
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by