How to convert timeseries class mat file to excel

50 views (last 30 days)
Facing probelm with timeseries class. i want to convert the mat file into excel. I have used the below code,but it's showing only the mat file name.
whos -file simout1.mat
Result: simout1
the problem is table b has another double timeseries cell. its difficult to convert into excel file form simout1.mat file.
Would you please help to convert into excel ? i have uploaded the mat file(simout1.mat) in google drive as i can not upload here.

Sign in to comment.

Accepted Answer

dpb on 26 Nov 2021
Edited: dpb on 26 Nov 2021
It's not bad at all...I let the file download overnight last night and got a few minutes to poke around just now...I was almost right yesterday. I renamed the timeseries to tsS locally for a shorter variable name...
>> ttS=array2timetable(tsS.Data(1:10,:),'RowTimes',seconds(tsS.Time(1:10)))
ttS =
10×4 timetable
Time Var1 Var2 Var3 Var4
________ ___________ ____ ____ __________
0 sec -6.0029e-06 0 0 6.4033e-06
0.05 sec -82.029 0 0 82.711
0.1 sec -81.195 0 0 81.864
0.15 sec -33.807 0 0 33.92
0.2 sec -34.5 0 0 34.618
0.25 sec -34.068 0 0 34.183
0.3 sec -33.664 0 0 33.777
0.35 sec -33.263 0 0 33.374
0.4 sec -32.865 0 0 32.974
0.45 sec -32.471 0 0 32.577
created the timetable ttS from the first 10 rows that match the image you posted.
>> ttS=array2timetable(tsS.Data,'RowTimes',seconds(tsS.Time));
>> whos ttS
Name Size Bytes Class Attributes
ttS 12096001x4 483841676 timetable
built the whole timetable in a pretty short amount of time...only a second or two here.
Of course, now you have a problem in that the maximum row limit in Excel is 1,048,576. This applies to Excel from Excel 2007 thru Microsoft 365 . Earlier versions were only 16K rows.
It'll take
>> tsS.Length/1048576
ans =
sheets if you were to try to go the absolute limit.
All in all, you're probably better off just leaving it in MATLAB in the timetable; it is simpler to deal with there although there is about a 25% memory penalty.
>> whos ttS tsS
Name Size Bytes Class Attributes
tsS 1x1 387072368 timeseries
ttS 12096001x4 483841676 timetable
Arif Hoq
Arif Hoq on 29 Nov 2021
found the idea to extract the table data into excel as you mentioned above. thank you very much @dpb. it was a tough time i guess.

Sign in to comment.

More Answers (2)

dpb on 25 Nov 2021
Edited: dpb on 25 Nov 2021
You've managed to put a timeseries object into a table as a cell. To do anything with it, you've got to dereference it back to the inherent timeseries.
In other words, "Don't do that!"
Work with the timerseries as it is; the timeseries object is a real oddball thingie -- it is quite cumbersome and not well supported in continuing development in that there are no methods like read/writetable that work with it.
To convert it to a real timetable, try some variation on
where you get the time information and the data from the timetable and put it into something more usable.
The events that may be with the timeseries will have to be dealt with in some other fashion -- I've never had a case of my own nor found one in all the responses to Q? here of the forum that I could not more easily solve with other tools than the timeseries, so I don't know all the ins and outs of it, but it always was limiting in some way for any problem I was ever faced with.
The file is too big to download practically here in available time...but I'm sure some variant of the above will get you where you need.
dpb on 26 Nov 2021
" add customized functionality into the class"
Which functionality will be, of course, some specific implementation of the process outlined above...

Sign in to comment.

Peter Perkins
Peter Perkins on 28 Nov 2021
In MATLAB R2021b, you can use timeseries2timetable, and then write the timetable to excel.
This timeseries has nothing complicated in it, so in earlier versions you can do something like what dpb suggests, but I'd recommend this slight variation that uses the SampleRate parameter:
tt = array2timetable(ts.Data,'StartTime',seconds(0),'SampleRate',20)
Peter Perkins
Peter Perkins on 2 Dec 2021
No, your carping has a purpose. Keep them fish coming.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!