Importing unequal text from text file
Ältere Kommentare anzeigen
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
Antworten (2)
Walter Roberson
am 30 Dez. 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
am 30 Dez. 2013
Bearbeitet: Azzi Abdelmalek
am 30 Dez. 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
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!