Textscan File and ignoring the newline characters

3 Ansichten (letzte 30 Tage)
How can I textscan a file and ignore newline characters?
  4 Kommentare
Walter Roberson
Walter Roberson am 17 Jan. 2014
What textscan command are you using?
Giorgos Papakonstantinou
Giorgos Papakonstantinou am 17 Jan. 2014
Bearbeitet: Giorgos Papakonstantinou am 17 Jan. 2014
tmp = textscan(fid, '%s%s%s%s%s%s%s%s%s%s' , 'delimiter', ',', 'headerlines', 1);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

AJ von Alt
AJ von Alt am 17 Jan. 2014
Bearbeitet: AJ von Alt am 17 Jan. 2014
You should use %q instead of %s when double quotation marks are used to indicate text that you want to keep together. Additionally, the parameter 'HeaderLines' should be set to 0 when there are not header lines to skip.
The following code produced the desired result for the attached input.
% Open the file
fid = fopen ('testinput2.txt' );
% number of consecutive strings to read
nString = 10;
% create the datafield template
formatSpec = repmat( '%q' , 1 , nString );
% parse the file
parsedText = textscan( fid, formatSpec , 'delimiter',...
',' , 'headerlines', 0, 'CollectOutput', 0 );
% Clean up
fclose(fid);

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings 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!

Translated by