I want to interpolate the values inside one column. Using Matlab -
the matrix looks this:
0 0 0.1 0 0.2 0 0.3 5 0.4 0 0.5 0 0 0 0.1 0 0.2 6 0.3 0 0.4 0 0.5 0
as can see simple matrix (x,y), want linearly interpolate values of column 2. how can ?
using interp1
linear
, extrap
option
%// taking non-zero rows b = a(all(a,2),:) %// performing linear interpolation on first column of 'a' 'interp1' out = interp1(b(:,1),b(:,2),a(:,1),'linear','extrap')
results:
b = 0.3000 5.0000 0.2000 6.0000 out = 8.0000 7.0000 6.0000 5.0000 4.0000 3.0000 8.0000 7.0000 6.0000 5.0000 4.0000 3.0000
if want them x
values
out = [a(:,1),out]
you get
out = 0 8.0000 0.1000 7.0000 0.2000 6.0000 0.3000 5.0000 0.4000 4.0000 0.5000 3.0000 0 8.0000 0.1000 7.0000 0.2000 6.0000 0.3000 5.0000 0.4000 4.0000 0.5000 3.0000
Comments
Post a Comment