필터 지우기
필터 지우기

How do I remove leading characters from a string?

조회 수: 3 (최근 30일)
pruth
pruth 2019년 9월 18일
댓글: Walter Roberson 2019년 9월 19일
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

채택된 답변

Walter Roberson
Walter Roberson 2019년 9월 18일
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
Walter Roberson
Walter Roberson 2019년 9월 18일
strjoin(segments(2:3), ' ')
Note that we no longer recommend using datenum: we recommend using datetime()
pruth
pruth 2019년 9월 18일
that works !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ankit
Ankit 2019년 9월 18일
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
Ankit
Ankit 2019년 9월 18일
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 2019년 9월 19일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by