Textscan reading in floats and str2num dropping ending zeros
Mostrar comentarios más antiguos
MATLAB VERSION: R2007a - I know...my company is up on the times.
I'm trying to read in data from a tab delimited text file that looks like:
ABCDEF 2012.190.18465.356 0 TRUE
MKJIJN 2012.190.19305.376 b7 183
My current scan string is:
SCAN_STR = '%s\t%f.%f\t%s\t%s\t%*s';
TEMP = textscan(FID, SCAN_STR, 'delimiter', '\t');
Matlab reads in the data as (sample of first to save time):
TEMP{1} = 'ABCDEF'
TEMP{2} = 2012.19
TEMP{3} = 18465.365
TEMP{4} = '0'
TEMP{5} = 'TRUE'
Why does it drop the ending zero for TEMP{2}? 19 vs. 190 is a big difference. Is there any way for me to make sure the ending zero remains?
When I try to read it in as a string:
SCAN_STR = '%s\t%s\%s\t%s\t%*s';
All are strings. Now:
TEMP{2} = '2012.190.18465.356'
I split it using:
YRDY = cellfun(@(x)x(1:8),TEMP{2},'Un',0);
YRDY = '2012.190'
Using str2num:
YRDYnum = cellfun(@(x)str2num(x), YRDY, 'Un',0);
YRDYnum = 2012.19
Why does this happen? There has to be some way for me to keep the ending zero.
Thanks, Mike
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!