0

I have a string of format

"'Year'-'Month'-'Day'T'Hour':'Minute':'Second'Z" for example '2020-11-26T16:56:09.676Z'

(Note the milliseconds are considered part of the second)

I would like to convert it to the format:

t1 = 1x6

2020 11 26 16 56 09.676

Or in other words a 1x6 array.

Note: This is to be completed using MatLab.

1 Answer 1

1

You can

  1. Use regexp with the 'match' input flag to detect the numbers as one or more digits (\d+) optionally followed by a decimal point (\.?) and then zero or more digits (\d*). This will give a cell array of strings.
  2. Apply str2double to convert the strings to numbers. This will give a numeric row vector.

s = '2020-11-26T16:56:09.676Z';
result = str2double(regexp(s, '\d+\.?\d*', 'match'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.