How to fill the gap with Nan
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Guillaume
el 2 de Feb. de 2015
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, :);
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!