Effacer les filtres
Effacer les filtres

how to write a array of string into a text file and how to read it back?

4 vues (au cours des 30 derniers jours)
For example, I have a an array called `namelist` contains the following strings on each column:
'img1.png'
'img10.png'
'img100.png'
'img2.png'
...
I would like to record this array into a txt file and later read it back. (what I need is the order of those files).
What I am trying now is use
dlmwrite('namelist.txt',namelist)
But it gives me a really ugly txt file which contains
I,m,g,1,.,p,n,g,I,m,g,1,0,.,p,n,g,I,m,g,1,0,0,.,p,n,g,I,m,g,1,0,1,.,p,n,g,I,m,g,2,.,p,n,g,
and I have no idea how to read it back, i.e., to have array `nameless` as it before. I tried `dlmread` and `textscan` but none of them works... or I don't know the right way.
Any ideas?

Réponse acceptée

Stalin Samuel
Stalin Samuel le 27 Oct 2015
file_name = 'namelist.txt' ;
for i = 1:length(namelist)
current_line = namelist{i};
dlmwrite(file_name, current_line ,'delimiter','','-append', 'newline', 'pc');
end
data = importdata(file_name )

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by