how do i use textscan to display strings have spaces in between ?
19 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Walter Roberson
2017-3-22
In that situation, you should
Pat = textscan(fidpw, format, 'whitespace', '', 'delimiter', ';');
6 个评论
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)
更多回答(1 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!