problem in read txt file

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일

0 개 추천

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

huda nawaf
huda nawaf 2012년 4월 17일
thanks ,
I ran it . but when write d(1)
got the first line:
d(1)
ans =
'?RKG','RCRE','?RFI'
can I get just '?RKG' when write d(1)?
huda nawaf
huda nawaf 2012년 4월 17일
I got
'poiugrtfyutr'
'trqwtyuipoyt'
this is not what I need
I need when write d(1) getn 'poiu' , d(2) get 'grtf' ...etc.
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개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by