This is an example of one dimensional data interpolation, which is required often for analysis and post processing purpose.
Suppose you have collected one data set from any standard book/research paper and let us introduce the data set as (X1,Y1).
Now you have done some simulation/experiments and obtained some data set as (X2,Y2).
Now both the data sets contains different values of x,y but you want to interpolate the (X1,Y1) data set into new (X2,Y1_new) set.
Matlab Code:
%% these are sample data set, use your own data set
X1=[0
1
2
3
4
5
6
7
8
9
10
];
Y1=[0
10
4
50
90
60
30
40
9
100
100
];
X2=[0
0.5
2.5
4
4.3
4.9
6
6.3
9
10
];
Y2=[0
2
6
10
50
6
80
90
90
100
];
%% code for interpolation
Y1_new(:)=interp1(X1,Y1,X2(:),'spline'); %% New Y(:)=interp1(old X,old Y, New X(:), 'spline')
Y1_new=Y1_new';
%% This will give the interpolated data set (X2,Y1_new)
%% for testing
figure
plot(X1,Y1);
figure
plot(X2,Y2);
figure
plot(X2,Y1_new);
--------------------------------------------------------------------------------------------------
Comments
Post a Comment