Spline interpolation in matlab

2 views (last 30 days)
Rachel Chung
Rachel Chung on 25 Mar 2015
Answered: dpb on 25 Mar 2015
I have the following:
x = 1:365;
y = T;
xx = missing;
yy = interp1(x,y,xx,'spline')
I have data `T`, which is 365 days of data, and `missing` is a vector containing the days on which the data is faulty. I need to generate estimated values at the missing days. However, when I use the above syntax, it returned a vector of all the same value. I made some changes, got an error, deleted them, and now with the same syntax I'm getting the error on line 4:
You can not subscript a table using only one subscript. Table subscripting
requires both row and variable subscripts.
What am I doing wrong?
  2 Comments
Christiaan
Christiaan on 25 Mar 2015
Dear Rachel,
Could you send us the mat-file of 'T' and 'missing'? A small example, how the interp1 function works, I have posted below for you.
clc; clear all; close all;
x = 1:365;
y = sin(x);
xx = [1 3 4];
yy = interp1(x,y,xx,'spline')
Kind regards, Christiaan

Sign in to comment.

Answers (1)

dpb
dpb on 25 Mar 2015
Your T vector has zero-valued entries for the missing locations and so there is a data value at that day and therefore interp1 returns that value (0) instead of an interpolated value.
T(missing)=[]; % remove the missing locations
t=1:365; t(missing)=[]; % the correlating full day vector
yy=interp1(t,T,missing,'spline')

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!