how do i use textscan to display strings have spaces in between ?

조회 수: 27 (최근 30일)
chocho
chocho 2017년 3월 22일
댓글: chocho 2017년 3월 22일
Hi friends, i have used this code with textscan:
fidpw= fopen('yy.txt','rt');
format = repmat('%s ',[1 row1]);
Pat = textscan(fidpw,format );
fclose(fidpw);
i used texscan to display the columns in this file but it doesn't work well because of the space existed in between the first rows of its corresponding columns
the columns looks like :
col1={stage iiib;t3;n1;m0}
col2={stage iv;t4;n1;m1}
code output looks like:
col1={stage;stage;t3;n1;m0}
col2={iiib;iv;t4;n1;m1}
?????
is this because i used %s in textscan ???
Thanks in advance!

채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 22일
In that situation, you should
Pat = textscan(fidpw, format, 'whitespace', '', 'delimiter', ';');
  댓글 수: 6
Walter Roberson
Walter Roberson 2017년 3월 22일
ncol = 12;
fmt = repmat('%s', 1, ncol);
fid = fopen('Classeur1.txt', 'rt');
Pat = textscan(fid, fmt, 'Delimiter', '\t');
fclose(fid)
chocho
chocho 2017년 3월 22일
@ Walter Roberson Great bro!
Works Well. the key point is the delimiter '\t'
Appreciate your help! Always perfect answers from you .

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

추가 답변 (1개)

KSSV
KSSV 2017년 3월 22일
fid = fopen('my text file','r');
S = textscan(fid,'%s','delimiter','\n') ;
fclose(fid) ;
S = S{1} ;
Note that S will be a cell. You can access your required line using S{i} . Where i is your line number.
  댓글 수: 1
chocho
chocho 2017년 3월 22일
code bug Error using textscan Buffer overflow (bufsize = 4095) while reading string from file (row 1 u, field 1 u). Use 'bufsize' option. See HELP TEXTSCAN. iic stage iia stage i stage iiic stage i stage iva stage iia stage iia stage i stage iii stage ii stage iv stage iiic stage iia stage iv stage iib NA stage iiib stage iiib stage iii stage iv stage iii
Error in Comparison (line 82) Patient = textscan(fidpw,'%s','delimiter','\n') ;

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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by