How do I remove leading characters from a string?

11 views (last 30 days)
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');

Accepted Answer

Walter Roberson
Walter Roberson on 18 Sep 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.

Sign in to comment.

More Answers (1)

Ankit on 18 Sep 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
Walter Roberson
Walter Roberson on 19 Sep 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.

Sign in to comment.


Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!