MATLAB Answers

0

How to find Missing data and insert Nan

Asked by fengsen huang on 30 Apr 2018
Latest activity Answered by dpb
on 30 Apr 2018
I have recorded data for 30 days and and the time interval for recording were 30 minutes which the first 30 minutes of day one is written as 25101.0 and the second 30 mins is 25102.0. The 251 means the 251st day of the year and 01 means the 1st 30 mins of the day. The data missed recording 1-23rd 30 mins of the day, I need to plot a graph and how can I add the missing value and imput NaN so I can analyse it?

  0 Comments

Sign in to comment.

2 Answers

Answer by CP
on 30 Apr 2018

Hi Fengsen,
It's hard to provide a solution without seeing how you have your data vector set-up in MATLAB, but I will try my best to provide you with some guidance.
If you know the indices that do not have data, you can simply write, NaN. For example:
data = [9 4 NaN 6];
time = [1 2 3 4];
plot(time,data,'x')
% Note, that the NaN occurs at the third time entry. Thus, make sure this time entry corresponds
% to the actual time of occurrence using your 25101.0 notation above.

  0 Comments

Sign in to comment.


Answer by dpb
on 30 Apr 2018

"25101.0 and the second 30 mins is 25102.0."
Then missing points will be where
ix = [diff(t) ~= 1 | diff(t) ~= -23] + 1;
Use those indices to infill the missing locations; note will have to work from rear forward or the index locations will change as the vector length grows.
Alternatively, for each day subsection you can find the subsection length as
ixday=find(diff(fix(t/100))==1);
and any that aren't the multiple of 25 will be short days and then you can interpolate what are found to infill the missing.

  0 Comments

Sign in to comment.