MATLAB: How to make the spline function only smooth existing data points and not smooth over NaNs

spline

Hello, I have a row vector of 40 values that represent coefficients of variation. I need to plot these points in a normal line graph, but understandably, this produces a very jagged line plot and I would like to smooth over the data. The spline function makes the best looking graphs, the problem is that I have a lot of NaNs within the 40 data points, but the fact that there are NaNs is valuable information that needs to remain also in the plot – I need the plot to have empty spaces where there is no data. My question is thus, is it possible to make the spline function smooth only data points that exist and to ignore NaNs by not filling them in? I don't want the NaNs interpolated but I want the data points I do have smoothed. (Note I have tried the smoothts function as well but the smoothing is mediocre at best).

Best Answer

Remove the NaNs when performing the spline fit. But when plotting, evaluate the spline at all the data points, including the NaNs.
Related Question