I tried many times to import a file with textscan, but there's always some problem. i.e. the data didnt display correctly.
Here is a few rows of my data, its actually not complicated
Station,East,North,Zinv,ResInv,Res0,Rerr0,dzW,Rerr,Rsns
"From RSTEMINV v3.30e Date:02/02/12 Time:10:26:56"
0,0,0,0,4.6440E+0,4.8214E+0,500,2,8.89,81.89
0,0,0,-2.5,4.6440E+0,4.8214E+0,500,2,8.89,81.89
0,0,0,-7.82,5.0684E+0,5.4622E+0,500,1,8.84,35.03
0,0,0,-13.82,6.1425E+0,6.6325E+0,500,1,12.56,49.84
0,0,0,-20.589,8.3816E+0,8.4243E+0,500,1,13,32.51
0,0,0,-28.223,1.1675E+1,1.0656E+1,500,1,15.36,23.87
and my code is
fid=fopen('TEM1D1_1.m1d');
A=textscan(fid,'%u',10,'headerline',2);
I dont know why, is it because this file badly formatted?
Anybody would like to give me a hand?
Thanks in advance.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Feb. 2012

0 Stimmen

The %u format is only for unsigned integers, but some of your data is signed (negative) and some of it is non-integer.
Use %g not %u

6 Kommentare

Lei
Lei am 2 Feb. 2012
Hi Walter,
Thanks, but this doesnt work.
I know that, i also tried to use u% s% etc. none of them works.
fid=fopen('TEM1D1_1.m1d');
A=textscan(fid,'%g',10,'headerlines',2);
??? Error using ==> textscan
Badly formed format string.
Lei
Lei am 2 Feb. 2012
and if i use this code
A=textscan(fid,'%s',10,'headerlines',2,'delimiter',',');
only returns one row of my data, this row looks right.
but only has one row, somewhere in the middle of my data
dont know why
Walter Roberson
Walter Roberson am 2 Feb. 2012
Sorry, should be %f rather than %g .
Lei
Lei am 2 Feb. 2012
thanks,
but the same thing, only one row showed up.
Walter Roberson
Walter Roberson am 2 Feb. 2012
The number, 10, that you give, is the number of repetitions of the format to use. When the format is '%f' or any other numeric form, that means to read 10 numbers, not 10 lines.
numcol = 10;
fmt = repmat('%f',1,numcol);
A = textscan(fid, fmt, 'headerlines', 2, 'delimiter', ',');
Lei
Lei am 18 Feb. 2012
Hi walter,
just saw ur reply today,its weird cauz i didnt get an email notice.
Yeah, you were right. I didnt realized that before.
Thanks for your help!
and your code works perfectly.
thanks again^_^

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

Lei
am 2 Feb. 2012

Bearbeitet:

am 15 Okt. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by