How do I remove leading characters from a string?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
pruth
am 18 Sep. 2019
Kommentiert: Walter Roberson
am 19 Sep. 2019
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
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 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.
3 Kommentare
Walter Roberson
am 18 Sep. 2019
strjoin(segments(2:3), ' ')
Note that we no longer recommend using datenum: we recommend using datetime()
Weitere Antworten (1)
Ankit
am 18 Sep. 2019
Hello Pruth,
a = extractBetween(dummy{1, 1}, 10,20)
where 10 is the start position and 20 is the end position.
Cheers
Ankit
3 Kommentare
Ankit
am 18 Sep. 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
am 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.
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!