How to 1-D interpolate data

6 views (last 30 days)
mananchaya vimolnoch
mananchaya vimolnoch on 21 Jun 2021
Commented: Walter Roberson on 21 Jun 2021
i have these data
vx = position in cm (x)
wx = radiation dose (y)
If i want to interpolate wx in to the new position (vq_x) this code went fine.
m_x_int = interp1(vx,wx,vq_x,'pchip');
If I have another radiation dose data (new_wx) , I want to determine its position by using vx and wx
the code should be
m_x_int = interp1(wx,vx,new_wx,'pchip');
but it can't because wx have many duplicate value what should I used instead if I dont want to exclude any data point

Answers (1)

Walter Roberson
Walter Roberson on 21 Jun 2021
You will need to break wx into monotonic segments (all increasing or all decreasing.) For each segment, test if new_wx is inside the segment, and if it is then interpolate with the corresponding segment of vx and add the result to the list; if new_vx is not inside the segment then do not add anything to the list. At the end, you would get zero or more results of vx values that are all as equally valid as each other.
For example,
t = linspace(0,1);
y = sin(2*pi*5*t + rand(size(t)));
plot(t, y)
Now your task is to report back every t location that matches y == 0.3, including the three places near 0.6
  2 Comments
mananchaya vimolnoch
mananchaya vimolnoch on 21 Jun 2021
This is how my data look like
Walter Roberson
Walter Roberson on 21 Jun 2021
For a range of relative doses, that is comparatively easy: you know to expect two results, one for negative coordinates and one for positive coordinates. But for a range of relative doses above approximately 0.95, the wobbles in the relative doses become important, and you need to break up into segments.
Hmmm.... here is an approach that might be faster:
%the below needs ROW VECTORS for the strfind() operation
mask = (wx - new_wx) >= 0;
starts = strfind([0 mask], [0 1]);
stops = strfind([mask 0], [1 0]);
starts is now a list of indices at which wx transitions from being less than to new_wx to being at least as much.
stops is a list of indices at which wx transitions from being at least as high as new_wx to being less than.
If you are careful with the boundary conditions and indices, interpolate "there" (you would need to figure out which side of the returned indices to start at for the interpolation.)

Sign in to comment.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!