How to keep NaNs in interp?
Show older comments
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 Comments
Steven Lord
on 26 Jan 2017
Can you show a (small) concrete example? Include the definition of a small data set with NaNs, the command you use to interpolate it, the command you use to plot it, and describe how you want/expect the plot to look.
Sancheet Hoque
on 26 Jan 2017
Steven Lord
on 26 Jan 2017
So what you've shown is u? Can you also show tarray and t_new?
Sancheet Hoque
on 26 Jan 2017
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!