From: H on
I came up with this not-so-elegant solution:
The idea is to find the first and last non-nan indexes and then replace the correspoding nans with them.

%vector
A=[
NaN
NaN
NaN
3
6
10
30
100
NaN
NaN];

%index of the first non-nan
ind1=find(~isnan(A),1,'first');
%index of the last non-nan
ind2=find(~isnan(A),1,'last');

%replace the nans in the beginning
A(1:ind1-1)=A(ind1);
%replace the nans in the end
A(ind2+1:end)=A(ind2);