Changing String Name in a For Loop

10 Ansichten (letzte 30 Tage)
Nathan Armani
Nathan Armani am 25 Jun. 2019
Kommentiert: Nathan Armani am 25 Jun. 2019
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 25 Jun. 2019
In that line replace
.item_(i)
with
.(sprintf('item_%d', i))
The () are important for this purpose.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by