I want to change [1 nan 1 2 2 nan nan 3 nan 4 nan nan 5] into [1 1.5 1 2 2 2 3 3 3.5 4 4 5 5]. If there is a single NAN, I want the NAN to be filled in with the average of the numbers before and after. If there is more than one NAN. I want the NAN to be filled in with the nearest number.
So far, I only have the code to find the single NAN's:
max_x = x(:, 2);
min_x = x(:, 3);
for jj = 1:length(max_x)
for kk = 1:length(min_x)
if isnan(max_x(jj))
max_x (jj) = ((max_x(jj-1)+max_x(jj+1))/2);
elseif isnan (min_x(kk))
min_x (kk) = ((min_x(kk-1)+min_x(kk+1))/2);
end
end
end
How do I fill in the NAN's that aren't single?
Much thanks.
Aucun commentaire:
Enregistrer un commentaire