Importing unequal text from text file
Afficher commentaires plus anciens
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
Réponses (2)
Walter Roberson
le 30 Déc 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
le 30 Déc 2013
Modifié(e) : Azzi Abdelmalek
le 30 Déc 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
Catégories
En savoir plus sur Large Files and Big Data dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!