# calculating a interpolation for a false data and inserting the calculated value back at its original place

1 view (last 30 days)
Sehoon Chang on 8 Apr 2020
Edited: Image Analyst on 8 Apr 2020
Hi all,
I am trying to insert my calculated interpolation value back to its original position.
I have a data, in which there are some outliers.
I located the outliers within the data, deleted them and calculated interpolated value at its position.
Now i am trying to insert interpolated value back at the original position of outlier
and draw diagram same as the original one shown as example (of course without the outliers peaking at the top)
Please give me advice as to how i can implement above mentioned problem in a more smooth way.
on x-axis, idx is the time variable;
on y-axis, W
plot(W(idx), 'b-');
stdDev = std(W(idx))
meanValue = mean(W(idx))
zFactor = 3 % usually, z factor of 3 -> outlier
outliers = find((abs(W(idx)-meanValue) > (zFactor * stdDev)) & (W(idx) > 20) ) % searching outlier location (based on z-score & Wärmemenge > 20)
count_outliers = length(outliers) % checking the total number of outliers
W(outliers) = [] % deleting / emptying the value at the outlier position
x = 1:17280 % a simple indices for x asix
x(outliers) = [] % deleting / emptying the value at the outlier position on x-axis
W_int = interp1(x',W,outliers)

Image Analyst on 8 Apr 2020
Edited: Image Analyst on 8 Apr 2020
Don't delete them! Just create a new array. Try something like (untested):
plot(W(idx), 'b-');
stdDev = std(W(idx))
meanValue = mean(W(idx))
zFactor = 3 % usually, z factor of 3 -> outlier
outliers = ((abs(W(idx)-meanValue) > (zFactor * stdDev)) & (W(idx) > 20) ) % searching outlier location (based on z-score & Wärmemenge > 20)
count_outliers = length(outliers) % checking the total number of outliers
fprintf('Found %d outliers.\n', count_outliers)
% Plot outliers
hold on;
plot(x(outliers), W(outliers), 'rv');
hold off;
% Replace outliers with interpolated data.
goodIndexes = ~outliers; % A logical vector.
x = 1 : length(W);
W_int = interp1(x(goodIndexes), W(goodIndexes), x);
The good indexes will just give you the original values but the outlier ones will be interpolated.
If it doesn't work, attach your W data in a .mat file with the paper clip icon.
You know there are isoutlier() and rmoutliers() functions, right?