Helping filling missing data with 0 value

조회 수: 15 (최근 30일)
Anh Vu
Anh Vu 2018년 4월 9일
댓글: Razvan Carbunescu 2018년 4월 11일
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

채택된 답변

David Fletcher
David Fletcher 2018년 4월 9일
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
Anh Vu
Anh Vu 2018년 4월 10일
Thank you so much
Razvan Carbunescu
Razvan Carbunescu 2018년 4월 11일
Can probably make this more compact with indexing
fullData = [(1:365)' zeros(365,1)];
fullData(data(:,1),2) = data(:,2);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by