Fill blank spaces from lagged data with NaN

조회 수: 2 (최근 30일)
Robert
Robert 2015년 12월 15일
편집: dpb 2015년 12월 16일
I have a code which lags one data set in relation to another. The lag is determined based on r^2 values previously figured out.
The problem I have is that when the data is lagged, some data is removed. For example where there is a lag of +1 a vector of 96 rows becomes a vector of 95 rows. I want to fill that missing row is NaN so that it remains at 96. See code below. Thank you in advance for any help.
clear all;
clc
lag = load ('lagtime.txt'); %File contains the time by which each column will be lagged
A1 = load ('data\Anomalies\TWSA1anomalies.mat');
Approx1x = A1.TWSA1anomalies;
Approx1y = reshape(Approx1x,[1505,96]);
Approx1z = Approx1y';
NDVIdata = load ('data\Anomalies\NDVIanomalies.mat');
NDVIx = NDVIdata.NDVIanomalies;
NDVIy = reshape(NDVIx,[1505,96]);
NDVIz = NDVIy';
for j = 1:1505
m = lag(1,j)
GRACEcrop = Approx1z(1:(96-m),j);
NDVIcrop = NDVIz((1+m):96,j);
dlmwrite ('GRACECROPVEC.txt',GRACEcrop,'-append');
dlmwrite ('NDVICROPVEC.txt',NDVIcrop,'-append');
end
GRACEVEC = load ('GRACECROPVEC.txt');
NDVIVEC = load ('NDVICROPVEC.txt');
NEWGRACELAG = reshape(GRACEVEC,[96,1505]);

채택된 답변

dpb
dpb 2015년 12월 15일
편집: dpb 2015년 12월 16일
Instead of selecting the first N points,
GRACEcrop = Approx1z(1:(96-m),j);
just set the last m to NaN...
Approx1z(end-m+1:end,j)=nan;
and then write the modified array. No need for a new array at all (unless you have reason to also keep the unmodified in memory as well, of course).
  댓글 수: 2
Robert
Robert 2015년 12월 15일
Thanks for your answer, however, it didn't seem to work, it made all of the output NaN. I'm also not sure that I understand your reference to changing the last m to NaN, as m is only 1 number per loop (generally 0-6).
dpb
dpb 2015년 12월 16일
Oops, missed fixing up the index...see correction above...

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by