# Interpolating data based on the time segments.

5 Ansichten (letzte 30 Tage)
DuckDuck am 28 Sep. 2015
Kommentiert: Peter Perkins am 28 Sep. 2015
Hello everybody,
I have a time series with the average sample 1 second but samples some time delay more or less than that. I want to interpolate between those segments so i will have a sampling rate of 10ms, ie. creating 100 samples out of that. I know how to do it with a loops and logical expressions but was wandering if matlab has functions and tricks to do it faster. This is a piece of data i want to interpolate.
t=[0
0.391912101000000
1.32177628400000
2.41211658700000
3.40585991000000
4.91603845400000
5.41236075000000
6.35266290000000
7.39591026800000
8.33071875300000
9.35080115800000
10.3286128480000
11.3210437940000
12.3288264900000
13.3216847220000
14.3908438870000
15.3411872390000
16.9984129380000
17.3812299690000
18.3304135490000
19.3526934200000
20.3328551780000
21.9144513930000
22.3394475780000
23.3421944120000
24.3500686680000
25.3540363150000
26.6359224740000
27.3324889320000
28.3450633250000]
so out of 30 samples i want to create around 2834 samples.
if i will create let say:
for i=2:length(t);
ti=[];
ti=t(i-1):0.1:t(i);
tn{i-1}=interp1((t(i-1):t(i)),(t(i-1,1):t(i,1)),ti);
end
will fail because
ti=[0 0.100 0.200 0.300]
which is not the same as
(t(i-1):t(i))=[0,0.39]
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Walter Roberson am 28 Sep. 2015
Presuming that you also have a data array that you want to interpolate:
new_t = t(1):0.01:t(end);
new_data = interp1(t, YourData, new_t);
##### 5 Kommentare4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
Peter Perkins am 28 Sep. 2015
effess, you said, "some times in the interval the data do not change and interpolation fails". Just for the record, interp1 expects the x values (time, in your case) to be monotonically increasing, but the y variable (or variabels in your case) can be anything. This, for example
interp1(data(:,1),data(:,2:end),0:.01:26.7)
will absolutely not fail.

Melden Sie sich an, um zu kommentieren.

### Kategorien

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!

Translated by