How to fill the gap with Nan

조회 수: 2 (최근 30일)
Khairul Afifi
Khairul Afifi 2015년 2월 2일
답변: Guillaume 2015년 2월 2일
Greetings,
I would like to ask on how to fill the gap with Nan. The file below show from 1 Feb 2013 to 13 Feb 2013, the data are missing. I would like to fill the missing data with Nan. Thank you in advance.

답변 (1개)

Guillaume
Guillaume 2015년 2월 2일
Build your cell array with the date/time including the missing values and NaN/empty strings everywhere else, and use intersect to fill it with the values you already have:
olddates = datenum(GAN_2013(:, 1), 'mm/dd/yyyy HH:MM'); %convert dates to numbers so we can get min and max
startdate = min(olddates);
enddate = max(olddates);
alldates = datestr(startdate:1/(60*24):enddate, 'mm/dd/yyyy HH:MM');
new_GAN = [num2cell(alldates, 2), cell(size(alldates, 1), 1), num2cell(nan(size(alldates, 1), 6))]; %destination cell array
%unfortunately, your dates are in format not supported by matlab, so convert them to the same format as new_GAN:
olddates = num2cell(datestr(olddates, ''mm/dd/yyyy HH:MM'), 2);
[~, inew, iold] = intersect(alldates, olddates);
new_GAN(inew, :) = GAN_2013(iold, :);

카테고리

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