Upload txt file with time units

1 visualización (últimos 30 días)
Lizan
Lizan el 24 de Mayo de 2013
Hi, I have a text file like,
13:43:51 26.0503 0.0000060763786
13:43:51 26.0503 0.0000085937353
13:43:51 26.0503 0.0000073350570
13:43:51 26.0503 0.0000073350570
13:43:52 26.0503 0.0000084201246
13:43:52 26.0503 0.0000072482512
13:43:52 26.0503 0.0000076388760
13:43:52 26.0503 0.0000093315811
13:43:52 26.0503 0.0000073350570
I would like to upload the time difference from the beginning, such as
1 26.0503 0.0000060763786
1 26.0503 0.0000085937353
1 26.0503 0.0000073350570
1 26.0503 0.0000073350570
2 26.0503 0.0000084201246
etc.,..
That is have the time display in seconds only. Any idea how to do this.
When using x = load('data.txt');
I get
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 24.9678 0.0008
14.0000 25.0020 0.0008
It seems to only take the first number.
Kind Regards,
That is I want to upload a vector of hh:mm:ss and then convert it to seconds.

Respuestas (1)

Walter Roberson
Walter Roberson el 24 de Mayo de 2013
fid = fopen('data.txt','rt');
datacell = textscan(fid, '%s%f%f');
fclose(fid);
datatimes = datenum(datacell{1}, 'hh:mm:ss');
timeoffset = datatimes - datatimes(1);
offsetsecs = round(timeoffset * 24*60);
newdata = [offsetsecs(:), datacell{2}, datacell{3}];
newdata will now be the array.
  1 comentario
Lizan
Lizan el 10 de Jun. de 2013
Editada: Lizan el 10 de Jun. de 2013
I only obtain,
newdata =
0 24
It does not seem to obtain the whole array..?
datacell =
{1x1 cell} [24] [0x1 int32] if I use %d
datacell =
{1x1 cell} [24] [0x1 double] if I use %f
Example of data:
14:42:21 24,0671 0,0000530381039
14:42:21 24,0671 0,0000508679695
14:42:22 24,0671 0,0000521700495
14:42:22 24,0671 0,0000539061584
14:42:22 24,0671 0,0000520832436
14:42:22 24,0671 0,0000530815050
14:42:22 24,0671 0,0000516492181
14:42:22 24,0671 0,0000504339404
14:42:22 24,0671 0,0000506075521
14:42:23 24,0671 0,0000529078934
14:42:23 24,0671 0,0000518662309
14:42:23 24,0713 0,0000519964378
14:42:24 24,0713 0,0000506943579
14:42:24 24,0713 0,0000507377590
14:42:24 24,0713 0,0000515624123
14:42:24 24,0713 0,0000503471346
14:42:24 24,0713 0,0000496092907
14:42:24 24,0713 0,0000521266446
14:42:25 24,0713 0,0000527342853
14:42:25 24,0713 0,0000523436611
14:42:25 24,0713 0,0000513453960

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by