How to 1-D interpolate data

조회 수: 3 (최근 30일)
mananchaya vimolnoch
mananchaya vimolnoch 2021년 6월 21일
댓글: Walter Roberson 2021년 6월 21일
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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 6월 21일
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
mananchaya vimolnoch
mananchaya vimolnoch 2021년 6월 21일
This is how my data look like
Walter Roberson
Walter Roberson 2021년 6월 21일
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.)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by