Importing unequal text from text file
Mostrar comentarios más antiguos
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
Respuestas (2)
Walter Roberson
el 30 de Dic. de 2013
cellfun( @(S) regexp(S, ',', 'split').', regexp(fileread('YourFile.txt'), '\n', 'split'), 'uniform', 0 )
This should give you columns across and rows down.
Azzi Abdelmalek
el 30 de Dic. de 2013
Editada: Azzi Abdelmalek
el 30 de Dic. de 2013
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
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!