Store values from for loop

2 vues (au cours des 30 derniers jours)
Alisher Narzulloev
Alisher Narzulloev le 31 Jan 2020
I am looping through files (using for loop) and getting two values from each loop - name and tag. What is the best way to store these values, if I later want to access tags using names?
  1. Is there anything similar to python dictionary: {'name1': tag1, 'name2': tag2, .... 'nameN': tagN}
  2. Or should it be stored in a table with two columns - name and tag
Thanks
  3 commentaires
darova
darova le 31 Jan 2020
What about simple char?
data= ['name1: tag1'
'name2: tag2'
'nameN: tagN']
Alisher Narzulloev
Alisher Narzulloev le 31 Jan 2020
Tag is one string value. I also believe table is the best approach. Thanks.

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 31 Jan 2020
names = cell(N,1) ;
tags = cell(N,1) ;
for i = 1:N % N is number of files
% get names and tages
names{i} = name ;
tags{i} = tag ;
end

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by