Add zero rows to a matrix with missing days

4 次查看(过去 30 天)
Hi! I went through all questions here but could not find a solution. I have a matrix 6519x20, first 5 columns are Month, Day, Year, Hour and Min. Next 25 are data. Each day has up to 227 values, some days have less data some days have more. There are days that are missing so it would look like an example on a picture where day 17 is missing.I need to determine missing days and insert missing zero rows into the matrix. I only need to insert one row per missing day as I will rearrange the data and swap matrix rows and columns later on. Therefore each day will have the same amount of data points.In the end I should receive a matrix of 6519+N of missing daysx20. Thanks!
  4 个评论
KL
KL 2017-11-27
I would suggest to use timetable for such data. Import your data as table and convert it into a timetable (just one column as datetime instead of 5). To fill out the missing data, there's a dedicated documentation,
Anton Shagin
Anton Shagin 2017-11-27
Thanks, KL. I believe I need to mention that I'm using 2011 version and readtable function was added in 2014.

请先登录,再进行评论。

回答(1 个)

MHZ
MHZ 2017-11-27
1. Import the excel sheet into Matlab using xlsread and prepare it as a matrix 2. You will need to convert the dates to their math equivalent in matlab using datnum. 3. Save the first row as is to a new matrix 4.Run a for loop by rows that will check the datenum with the one next to it. If the difference is 0 or 1, then write the next row to the new matrix. else add the missing number(s) with rows of zeros. The amount of the difference will tell you how many rows to add. Example, if the difference is 2, then add 1 row, if 3 then 2 rows,....basically n-1.
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by