To eliminate the lines begin with "%"
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
aneps
am 25 Nov. 2013
Beantwortet: Image Analyst
am 26 Nov. 2013
I have a file (attached here) which I need to eliminate all the lines begin with "%" and remove the "commas" after the numbers. Then read the numbers and put in separate columns X, Y and Z. Can anyone help me to make the program?
2 Kommentare
Akzeptierte Antwort
Simon
am 25 Nov. 2013
Hi!
Read in your file:
% read in a file
fid = fopen(FileName);
FC = textscan(fid, '%s', 'delimiter', '\n');
fclose(fid);
FC = FC{1};
You can get rid of all "%" lines if you compare the first char like:
FC = FC(~strncmp('%', FC, 1));
You can get rid of all ',' with a regex like:
FC = regexprep(FC, ',', '');
Afterwards you can parse your cell array FC line-by-line with sscanf to extract numbers.
3 Kommentare
Simon
am 26 Nov. 2013
Hi!
It seems that sscanf fails for some reasons I don't know. But you can as well use
% use sscanf for each cell
A = cellfun(@(x) sscanf(x, '%f %f %f'), FC, 'UniformOutput', false);
% convert from cell array to numeric array
A = [A{:}].';
Weitere Antworten (1)
Image Analyst
am 26 Nov. 2013
Why not just use importdata() where you can tell it to throw away some number of headerlines?
0 Kommentare
Siehe auch
Kategorien
Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!