Add zero rows to a matrix with missing days

조회 수: 1 (최근 30일)
Anton Shagin
Anton Shagin 2017년 11월 27일
답변: MHZ 2017년 11월 27일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by