Textscan File and ignoring the newline characters

조회 수: 3 (최근 30일)
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014년 1월 17일
댓글: Giorgos Papakonstantinou 2014년 1월 17일
How can I textscan a file and ignore newline characters?
  댓글 수: 4
Walter Roberson
Walter Roberson 2014년 1월 17일
What textscan command are you using?
Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014년 1월 17일
편집: Giorgos Papakonstantinou 2014년 1월 17일
tmp = textscan(fid, '%s%s%s%s%s%s%s%s%s%s' , 'delimiter', ',', 'headerlines', 1);

댓글을 달려면 로그인하십시오.

채택된 답변

AJ von Alt
AJ von Alt 2014년 1월 17일
편집: AJ von Alt 2014년 1월 17일
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);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by