Missing days and data in data file
1 view (last 30 days)
Show older comments
I have imported a data file and the data file has the following issue Some of the days are missing eg- 12-11-2011 then it jumps to 14-11-2011 so it misses the day 13-11-2011
So what i need to do is to create a new row in the places of the missing date. And that row must have the date of the missing data as well as all the data entires should be NaN.
eg= 13-11-2011 NaN NaN NaN NaN
This is the data given to me (Its way longer so i just took a portion of it)
A =
735876 10.2 10.8 10.21 29.1
735873 49.1 21.4 48.11 51.14
735870 41.2 45.1 42.1 55.1
735865 21.2 24.1 52.5 52.6
735863 52.5 52.5 63.6 11.22
735862 44.4 42.1 42.2 11.5
I use datestr command to convert the first column values to dates. Please suggest a code to fix this issue.
Regards, Luka.
0 Comments
Answers (2)
Guillaume
on 9 Jan 2015
How about:
fullrange = min(A(:, 1)):max(A(:, 1));
missingdates = setdiff(fullrange, A(:, 1))';
fullA = sortrows([A; [missingdates nan(numel(missingdates), size(A, 2)-1)]])
0 Comments
Star Strider
on 9 Jan 2015
This seems to work:
A = [735876 10.2 10.8 10.21 29.1
735873 49.1 21.4 48.11 51.14
735870 41.2 45.1 42.1 55.1
735865 21.2 24.1 52.5 52.6
735863 52.5 52.5 63.6 11.22
735862 44.4 42.1 42.2 11.5];
dvc = [A(1,1):-1:A(end,1)]';
B = nan(length(dvc),size(A,2));
[BiA,ia,ib] = intersect(A(:,1), dvc);
B(:,1) = dvc;
B(ib,2:end) = A(ia,2:end); % Output Matrix
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!