Helping filling missing data with 0 value

14 visualizaciones (últimos 30 días)
Anh Vu
Anh Vu el 9 de Abr. de 2018
Comentada: Razvan Carbunescu el 11 de Abr. de 2018
Hi everyone,
I have a data in the attachment. The left column represents all days from 1 to 365, but it is missing some values. I want to add missing values in the left column and 0 in the right column coresspondingly. Anyone can give me solutions. Thank you

Respuesta aceptada

David Fletcher
David Fletcher el 9 de Abr. de 2018
data=importdata('test.txt')
fullList=[(1:365)' zeros(365,1)];
partList=data(:,1);
isPresent=ismember(fullList,partList);
index=1;
missingVal=0;
for iter=1:365
if isPresent(iter)
fullList(iter,2)=partList(index);
index=index+1;
else
fullList(iter,2)=missingVal;
end
end
  2 comentarios
Anh Vu
Anh Vu el 10 de Abr. de 2018
Thank you so much
Razvan Carbunescu
Razvan Carbunescu el 11 de Abr. de 2018
Can probably make this more compact with indexing
fullData = [(1:365)' zeros(365,1)];
fullData(data(:,1),2) = data(:,2);

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by