MATLAB: Interpolation of zero values ​​in matlab

interpolationMATLAB

Hello! The readings from the gas sensor look like this: 70 71 0 69 0, at a temperature of 12 12.2 12.1 11.9 11.2. I try to interpolate all zero values, but for some reason I don’t consider it at all
[cat,nocat]=min(Animals); %readings from a 1x1200 thermometer
[dog,nodog]=max(Animals); % gas sensor reading 1x1200
for i=1:length(cat)
if dog(i)<0 % if some indication is less than 0 (they are all positive)
interpol(i)=dog(i); % the location of these zeros and this is what we interpolate (1 and the last value are not zero)
c(i)=interp1(interpol(i),cat(i),nearest); % interpolate;
else(i) dog(i)>0 % if the values ​​are greater than 0
c(i)= dog(i); % That testimony and remain
end
end

Best Answer

Try this: (Note that "cat" is not a good variable name because it is a Matlab function)
[cat,nocat]=min(Animals); %readings from a 1x1200 thermometer
[dog,nodog]=max(Animals); % gas sensor reading 1x1200
vq = interp1(cat(dog>0),dog(dog>0),cat(dog<=0),'nearest','extrap'); %nearest or other interpolation method you want
dog(dog<=0) = vq;