How can I stop textread from reading [1x1 char] and ' '?

2 views (last 30 days)
Hello all, I am trying to read data from a .txt file in the form of:
name; Date; web;
AB7103G2; "December2, 1992"; 8.759000;
When I read it using textscan and then text read...
c=textscan(fid, '%s %q %s');
[a,b,c]=textread(file,'%s %q %s')
...I will ger a result like:
a=
'name;'
[1x1 char]
'AB7103G2'
[1x1 char]
'AB9902G4'
or
b=
'Date;'
''
'December2, 1992'
''
How can I get rid of the [1x1 char] and the '' in my results for test read?
Thank you, kelsey

Answers (1)

Kelly Kearney
Kelly Kearney on 15 Jul 2014
It looks like there might be some additional characters/columns in your file that are causing problems; just running a test on your small example seems to work fine.
txt = sprintf('%s\n', 'name; Date; web;','AB7103G2; "December2, 1992"; 8.759000');
c = textscan(txt, '%s%q%s', 'delimiter', ';', 'headerlines', 0, 'collectoutput', true);
c{1}
ans =
'name' 'Date' 'web'
'AB7103G2' 'December2, 1992' '8.759000'
Note that I also specified a few extra options that you may or may not want to keep. Can you attach a small sample file to so we can see what might be the issue?

Community Treasure Hunt

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

Start Hunting!