Changing String Name in a For Loop

조회 수: 13 (최근 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 CenterFile Exchange에서 Loops 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