Importing unequal text from text file
이전 댓글 표시
I've got a file with the following format
if true
"abc","def","ada","bla"
"F52","L33"
.
.
.
end
with more lines following, generally all with a different number of " " entries per line.
So far I was able to import the file with textscan but it gets saved into a single column. I need each line to be a row and the strings inside the "" to be col entries. I think I can work with multiple arrays(one each line) or with an array filled with NaNs to fill the empty spaces, but have no idea how to separate the file after import
답변 (2개)
Walter Roberson
2013년 12월 30일
cellfun( @(S) regexp(S, ',', 'split').', regexp(fileread('YourFile.txt'), '\n', 'split'), 'uniform', 0 )
This should give you columns across and rows down.
Azzi Abdelmalek
2013년 12월 30일
편집: Azzi Abdelmalek
2013년 12월 30일
fid = fopen('file.txt');
res={};
while ~feof(fid)
res{end+1,1} =fgetl(fid);
end
fclose(fid);
a=regexp( res,'(?<=")[^",]+(?=")','match')
n=cellfun(@numel,a)
for k=1:numel(a)
out(k,1:n(k))=a{k};
end
out
카테고리
도움말 센터 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!