Azzera filtri
Azzera filtri

How to fill the gap with Nan

2 visualizzazioni (ultimi 30 giorni)
Khairul Afifi
Khairul Afifi il 2 Feb 2015
Risposto: Guillaume il 2 Feb 2015
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.

Risposte (1)

Guillaume
Guillaume il 2 Feb 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, :);

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by