Store values from for loop
Mostra commenti meno recenti
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?
- Is there anything similar to python dictionary: {'name1': tag1, 'name2': tag2, .... 'nameN': tagN}
- Or should it be stored in a table with two columns - name and tag
Thanks
3 Commenti
Stephen23
il 31 Gen 2020
What size and class does the tag have? If they are numerics of the same size, then put them into one numeric array, as this will make your data processing simpler. A table would likely be the best choice for what you described so far.
darova
il 31 Gen 2020
What about simple char?
data= ['name1: tag1'
'name2: tag2'
'nameN: tagN']
Alisher Narzulloev
il 31 Gen 2020
Risposte (1)
KSSV
il 31 Gen 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
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!