MATLAB: How to edit a text file using MATLAB

editMATLAB

Hello,
I have a text file that is in the following form:
"1981-02-01",15.3
"1981-02-02",18.8
"1981-02-03",21.9
"1981-02-04",19.9
I want to edit these two line and make it like as shown below:
1 15.3
2 18.8
3 21.9
4 19.9
I am looking for a MATLAB function that does this automatically without having to change my file manually because the original file contains 500 lines.
thank you

Best Answer

Try this:
textfile = {"1981-02-01",15.3
"1981-02-02",18.8
"1981-02-03",21.9
"1981-02-04",19.9};
T1 = cell2table(textfile);
T1.textfile1 = datetime(T1.textfile1, 'InputFormat',"yyyy-MM-dd");
T2 = [day(T1.textfile1) T1.textfile2]
producing:
T2 =
1 15.3
2 18.8
3 21.9
4 19.9
For your text file, use readtable to import it as a table. I use cell2table here for obvious reasons.