I assume you just have NaN
's in your data vector A
and your x-axis vector B
is alright?
For example take a equidistant time vector t
from 1 to 100. And a data vector x
where every tenth value is NaN
:
% example data
t = 1:100;
x = 100*t-t.^2;
x(10:10:end) = NaN;
Now take all values of t
and x
which are not NaN
as sample points and interpolate them with the complete time-vector t
as query points.
xi = interp1( t(~isnan(x)), x(~isnan(x)) , t, 'cubic');
or a little more complex for your case:
% example data
B = (1:4000)'; % 4000x1 double
A = repmat(1000*B-B.^2,4,1)'; % 4000x4 double
A(randi(400,40,1)) = NaN; % random NaNs in your data matrix
Ai = zeros(size(A));
for ii = 1:size(A,2);
tmp = A(:,ii);
Ai(:,ii) = interp1( B(~isnan(tmp)) , tmp(~isnan(tmp)) , B, 'cubic');
end
and the loopless alternative:
C = num2cell(A,1);
Ci = cellfun(@(x) interp1( B(~isnan(x)), x(~isnan(x)), B,'cubic'), C, ...
'UniformOutput',false);
Ci = cell2mat(Ci')';