How to do linear interpolation for a vector corresponding to a constant section? For example we have a matrix of two column as follow.
Matrix =
125.2985 5.7057
125.2991 5.7098
125.2997 5.6880
125.3004 5.6739
125.3010 5.7140
125.3016 6.0141
125.3022 6.3620
125.3029 6.4793
125.3041 6.4665
125.3047 6.4646
125.3053 6.4844
125.3060 6.4743
125.3066 6.4865
125.3072 6.4878
125.3078 6.4975
125.3085 6.4952
125.3091 6.4958
125.3128 6.5867
125.3134 7.0733
125.3141 7.3427
125.3147 7.3238
125.3153 7.3093
125.3159 7.3188
125.3166 7.3436
A second matrix is as 'C'.
C =
125.2985 2.0000
125.3004 3.0000
125.3053 5.0000
125.3085 4.0000
125.3147 6.0000
125.3166 7.0000
Now I need to do interpolation of 'C(:,2)' values for 'Matrix(:,1)'. The out put result of linear interpolation is as follow
Cinter=interp1(C(:,1),C(:,2),Matrix(:,1),'linear')
Cinter =
2.0000
2.3158
2.6316
3.0000
3.2449
3.4898
3.7347
4.0204
4.5102
4.7551
5.0000
4.7813
4.5937
4.4063
4.2187
4.0000
4.1935
5.3871
5.5806
5.8065
6.0000
6.3158
6.6316
7.0000
But I want to do interpolation only for those data points where 'Matrix(:,2)' is fairly stable. The rest should be as NaN in the interpolated vector. The required output should be as follow instead of 'Cinter'. How to achieve this?
output1=
2.0000
2.3158
2.6316
3.0000
NaN
NaN
NaN
NaN
NaN
NaN
5.0000
4.7813
4.5937
4.4063
4.2187
4.0000
NaN
NaN
NaN
NaN
6.0000
6.3158
6.6316
7.0000
This also can be taken a step further to achieve a second desired output. Based on first 'output1' data points (NaN) at constant 'Matrix(:,2)' can be replaced by nearby 'C(:,2) value'. The second output would be as follow and how to get this?
output2=
2.0000
2.3158
2.6316
3.0000
3.0000
NaN
NaN
5.0000
5.0000
5.0000
5.0000
4.7813
4.5937
4.4063
4.2187
4.0000
4.0000
4.0000
NaN
6.0000
6.0000
6.3158
6.6316
7.0000
Thank you very much. Best regards