MATLAB: How I do a Linear extrapolation

extrapolationlinearMATLAB

Hi, I have a matrix with 160 numbers, but the first values is nan. How I complete this matrix? Anyone help me? I try the — interp1 — but I have only a matrix, I do not have a vector to realize the extrapolation.
Thank you for your attention. Best wishes, Paulo Oliveira

Best Answer

This works:
% Original vector:
x = 1:10
% Replace the first 4 elements with ‘NaN’:
x(1:4) = NaN
% Create empty elements for the ‘NaN’ elements:
x(isnan(x)) = []
% Extrapolate to fill the empty elements:
xm = interp1(x, -3:0, 'linear', 'extrap')
produces:
xm =
1. 2 3 4