필터 지우기
필터 지우기

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?

채택된 답변

Stalin Samuel
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개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by