How to keep NaNs in interp?
조회 수: 23 (최근 30일)
이전 댓글 표시
I have an array that contains both NaNs and values. I'm plotting this values to compare to another dataset and if there is a long string of NaNs, interp simply ignores them and interpolates between the point before the first NaN and the point after the last NaN. This kind of throws off my comparison and I would rather have more NaNs so it's blank in the plot to show that no data was not found. Below is the code I used to interpolate array u (array u is the picture shown below). After I interpolated it the warning sign below showed. In the plot I attached the red line is the plot after it has been interpolated. I do not want a constant line like that, but rather an empty space wherever a NaN is, but the NaNs are removed during the interpolation. Is there a way to just interpolate the values and just increase the number of NaNs in the new interpolation? The picture with the datenums is the tarray. tnew is a little large, but I have inserted the code that creates it.
N = (numel(tarray)-1)*359 + numel(tarray);
t_new = linspace(tarray(1),tarray(end),N).';
u_newp = interp1(tarray,u,t_new,'pchip');
plot(t_new,u_new,'-b')
hold on
plot(t_new,u_newp,'-r')
title(sprintf('Path Comparasion of %s', baseFileName))
xlabel('Time')
ylabel('East Velocity m/s')
hold off
datetick('x','HH:MM:SS','keepticks')
legend('HF Data','Hycom Prediction')


Warning: Columns of data containing NaN values have been ignored during interpolation.
> In interp1>Interp1DStripNaN (line 241)
In interp1 (line 171)
In PathComp (line 119)
댓글 수: 4
채택된 답변
Matt J
2017년 1월 26일
편집: Matt J
2017년 1월 26일
Couldn't you just put the NaNs back in u_newp?
u_newp(idx)=nan;
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!