Interpolation is wrong?

조회 수: 1(최근 30일)
Shayma Al Ali
Shayma Al Ali 2021년 11월 15일
편집: Sulaymon Eshkabilov 2021년 11월 15일
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:
figure(8787)
subplot(2,1,1)
plot(wcdate_av,wc_average,'-k')
xlabel('date')
title('OG')
subplot(2,1,2)
plot(cr_2012.datetime,WC_cap,'-k')
xlabel('date')
title('Interpolated')
What could be the reasoning behind the wrong interpolation? I've tried every method of interpolation and they all yield the same results.

답변(2개)

KSSV
KSSV 2021년 11월 15일
x=dep_cal2012; % 977x1
y=wc_average; % 78x1
ix = linspace(1, numel(y), numel(x));
WC_interp = interp1(1:numel(y), y,ix,'nearest');
WC_cap=WC_interp';

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 11월 15일
편집: Sulaymon Eshkabilov 2021년 11월 15일
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