Changing String Name in a For Loop

10 ビュー (過去 30 日間)
Nathan Armani
Nathan Armani 2019 年 6 月 25 日
コメント済み: Nathan Armani 2019 年 6 月 25 日
Hello
Could you please help me with the following loop. I want to change Item number in every iteration. for exapme when i==1, it reads:
ProtocolName{i}=DIIinfoT.DirectoryRecordSequence.Item_1.ProtocolName;
when it is 2, it reads
ProtocolName{i}=DIIinfoT.DirectoryRecordSequence.Item_2.ProtocolName;
etc.
for i=1:500
ProtocolName{i}=DIIinfoT.DirectoryRecordSequence.Item_(i).ProtocolName;
end

採用された回答

Walter Roberson
Walter Roberson 2019 年 6 月 25 日
In that line replace
.item_(i)
with
.(sprintf('item_%d', i))
The () are important for this purpose.
  1 件のコメント
Nathan Armani
Nathan Armani 2019 年 6 月 25 日
Thank you so much. It worked.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by