Interpolation is wrong?

1 view (last 30 days)
Shayma Al Ali
Shayma Al Ali on 15 Nov 2021
Edited: Sulaymon Eshkabilov on 15 Nov 2021
Hi everyone!
I have a variable, 'wc_average' that I'd like to interpolate so it's the same size as another variable 'dep_cal2012'. Wc_average is about 78x1 and 'dep_cal2012' is about 977x1. The spacing between every point in wc_average is about every 10 minutes while the spacing between every measurement in dep_cal2012 is every nanosecond (there are about 7 measurements taken within the same second). I've tried interpolating wc_average with this code:
x=dep_cal2012; y=wc_average;
ix = linspace(1, numel(x), numel(y));
WC_interp = interp1(ix, y, 1:numel(x),'nearest'); WC_cap=WC_interp';
However, I've tried comparing the timeseries between the two and the interpolated one isn't right.
The code to run the figure:
What could be the reasoning behind the wrong interpolation? I've tried every method of interpolation and they all yield the same results.

Answers (2)

KSSV on 15 Nov 2021
x=dep_cal2012; % 977x1
y=wc_average; % 78x1
ix = linspace(1, numel(y), numel(x));
WC_interp = interp1(1:numel(y), y,ix,'nearest');

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 15 Nov 2021
Edited: Sulaymon Eshkabilov on 15 Nov 2021
Here is the corrected code:
x=dep_cal2012; y=wc_average;
ix = linspace(1, max(x), numel(y));
WC_interp = interp1(ix, y, x,'nearest'); WC_cap=WC_interp';

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by