how to write a array of string into a text file and how to read it back?
4 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Stalin Samuel
2015-10-27
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 )
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!