MATLAB: Take string input and reformat as cell array

string formattextscan

I would like to convert a string into a cell array. Here is a small example of string:
[{"ts": "2018-07-03T06:30:07", "v": 1.0}, {"ts": "2018-07-03T06:30:12", "v": 0.0}, {"ts": "2018-07-03T08:41:06", "v": 1.0}]
I would like to convert this into the following format:
[ datetime ] [number]
The ts and v refer to timestamp and value, and are not important to keep.
I believe using the textscan is an efficient way to do it, however I cannot figure out how to use it properly, any help is appreciated!

Best Answer

>> str = fileread('SampleData.txt');
>> str = regexprep(str,{'",','[":{}\[\]]+'},{' ',''});
>> fmt = '%*s%{yyyy-MM-dd''T''HHmmss}D%*s%f';
>> out = textscan(str,fmt,'EndOfLine',',');
Checking the output:
>> out{1}
ans =
2018-07-01T101102
2018-07-01T101107
2018-07-01T101109
2018-07-01T101114
2018-07-01T101120
2018-07-01T101125
etc.