problem in read txt file

1 次查看(过去 30 天)
hi, if I have txt file test.txt : 'poiu' 'grtf' 'yutr' 'trqw' 'tyui' 'poyt'
f=fopen(''test.txt'); d=fscanf(f,'%s'); I want d(1) be 'poiu' d(2) be 'grtf'.....etc
I do not want it d(1) be ' ,and d(2)be p
is there any solution for this problem?
thanks in advance, huda

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-4-17
f = fopen('test.txt')
c = textscan(f,'%s');
fclose(f)
d = cellfun(@(x)x(2:end-1),c{1},'un',0)
EDIT
on comment
f = fopen('test.txt');
c = textscan(f,'%s','Delimiter',',');
fclose(f);
d = regexprep(c{1},'''','')
more variant
f = fopen('test.txt');
c = textscan(f,'%s','Delimiter','''');
fclose(f);
d = c{:}(2:2:end)
  4 个评论
Andrei Bobrov
Andrei Bobrov 2012-4-17
That contains your test.txt?
huda nawaf
huda nawaf 2012-4-17
No this is txt file contains
'poiu' 'grtf' 'yutr'
'trqw' 'tyui' 'poyt'

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specialized Messages 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by