Changing String Name in a For Loop

27 vues (au cours des 30 derniers jours)
Nathan Armani
Nathan Armani le 25 Juin 2019
Commenté : Nathan Armani le 25 Juin 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

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Juin 2019
In that line replace
.item_(i)
with
.(sprintf('item_%d', i))
The () are important for this purpose.
  1 commentaire
Nathan Armani
Nathan Armani le 25 Juin 2019
Thank you so much. It worked.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by