0

I have a large cell array and I'm trying to vectorize some string parsing. The cell is 100000 x 1 and looks like this:

data =   
'"2016-07-27T14:18:08.519Z"'  
'"2016-07-27T14:18:16.549Z"'  
'"2016-07-27T14:18:21.544Z"'  
'"2016-07-27T14:18:27.517Z"'  

I want to parse this into two cell arrays that look like this:

date_str, which would look like this:

'2016-07-27'  
'2016-07-27'  
'2016-07-27'  
'2016-07-27'  

time_str, which would look like this:

'14:18:08.519'  
'14:18:16.549'  
'14:18:21.544'  
'14:18:27.517'  

I have looked at using cellfun(@strsplit,data), but it doesn't let me specify a delimiter for the "strsplit" function.

1 Answer 1

1

You can use regexprep to remove the double quotes, and then regexp (with the 'split' option) to split at the desired character. I'm assuming the splitting criterion is simply the occurrence of 'T'.

data = regexprep(data, '^"|"$',''); % remove double quotes
result = regexp(data, 'T', 'split'); % split at 'T'
result = vertcat(result{:}); % un-nest cell array
date_str = result(:,1);
time_str = result(:,2);
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.