How do I remove leading characters from a string?

I read one ascii file. and created this dummy mat file (attached ).
To make simple matrix out of it i need to split the string
i used this code (below) but it coudnt split the first string which is a date and time with some leading number since there is no space in between. There is this number before the date and time, i want remove those numbers so can use datenum on that string !
for i = 1:len_data
segments = regexp(dummy{1,1}{i,1},' ', 'split');
end

 Respuesta aceptada

Walter Roberson
Walter Roberson el 18 de Sept. de 2019
segments = regexp(dummy{1,1}{i,1}, '\t', 'split');
Perhaps you could have used readtable() on the ascii file: it would likely have detected the tab delimiter.

3 comentarios

pruth
pruth el 18 de Sept. de 2019
Hi walter, thanks for the reply !
your code works fine ! but here even date and time also splits. can you tell me how can just merge 2nd column(date) and 3rd column (time) to use datenum on it !
strjoin(segments(2:3), ' ')
Note that we no longer recommend using datenum: we recommend using datetime()
pruth
pruth el 18 de Sept. de 2019
that works !

Iniciar sesión para comentar.

Más respuestas (1)

Ankit
Ankit el 18 de Sept. de 2019
Hello Pruth,
One possibility is to use extractBetween command.
a = extractBetween(dummy{1, 1}, 10,20)
where 10 is the start position and 20 is the end position.
Based on your requirement you can also try extractAfter, extractBefore
Cheers
Ankit

3 comentarios

pruth
pruth el 18 de Sept. de 2019
hi, ankit thanks for the reply !
i used 'extractafter' as you suggested ! it does what I was expecting but i am not able to figure out how convert this cell into normal matrix with 1st coulmn having date and time in matlab format. i want to use datenum here !
i want to create simple matrix.
1st coulmn should be date and time(in matlab format) and next coumns should be data !
I appreciate your help !
Ankit
Ankit el 18 de Sept. de 2019
hello pruth,
cell data can be converted to double using str2double. But you can't use it to convert date, it will return a NaN value.
thanks
Ankit
Walter Roberson
Walter Roberson el 19 de Sept. de 2019
However, datetime() is happy to process cell array of character vectors ;-)
Also, in newer releases, duration() is happy to process cell array of character vectors. This was not possible in older releases.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Preguntada:

el 18 de Sept. de 2019

Comentada:

el 19 de Sept. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by