Finding smaller and larger values than user's input for 2D interpolation

2 visualizaciones (últimos 30 días)
Hi,
I have the following 3 matrices:
r_sp [1000x360]
theta_sp [1000x360]
Dose_alpha_total [1000x360]
Given a specific r and theta, the 3rd matrix (Dose_alpha_total) should output the matching dose.
Say there's this user's input: (r_in, theta_in)=(0.25, 90), which doesnt exist in r_sp & theta_sp (however, there are many other values which are really close to this given input).
The user must receive the dose at the inesrted point exactly - Dose_alpha_total(0.25,90).
In order to solve this, I was thinking of the following:
  • Find the closest points to the user's input, then find the corresponding dose (for instance, dose1 and dose2, matching to r=0.2493 & theta=89.92 and r=0.2494 & theta=89.93 respectively (which exist in my matrices))
  • Interpolate dose1 and dose2 to the exact same value the user asked for
So, for the first bullet, I wrote:
r_diff=abs((r_sp- r_in)./r_sp);
theta_diff=abs((theta_sp -theta_in)./theta_sp);
add=r_diff+theta_diff;
[M,I] = min(add(:));
[I_row1, I_col1] = ind2sub(size(add),I);
dose1=Dose_alpha_total(I_row1,I_col1);
theta_sp(I_row1,I_col1)=999; % "ruin" the index of the smallest value found with a different, very large value, in order to be able to find the 2nd smallest
r_sp(I_row1,I_col1)=999; % like above
r_diff=abs((r_sp- r_in)./r_sp);
theta_diff=abs((theta_sp -theta_in)./theta_sp);
add=r_diff+theta_diff;
[M,I] = min(add(:));
[I_row2, I_col2] = ind2sub(size(add),I);
dose2=Dose_alpha_total(I_row2,I_col2);
However, in order to be able to interpolate, I must have one point which is smaller than of the user's input and a second point which is larger.
The above code doesnt neccesairly meet this criteria. On the contrary - both the r's & theta's I got, were smaller than the user's input, hence not allowing me to perform the inerpolation.
Any clues of how to proceed?
In addition, as I'm quite new to matlab, I'm so not sure I fully understood how to use the built-in interpolation functions available. So when I'm past the first issue, how can I perform the interpolation? should I use interp2 function with these parameters:?
interp2(X,Y,V,Xq,Yq)
where: X = [I_row1, I_col1] ---> it should be a single value though, not a 1x2 array... right?
Y = [I_row2, I_col2] ---> likewise?
V=[Dose_alpha_total(I_row1, I_col1), Dose_alpha_total(I_row2, I_col2)]
Xq = ?
Yq =?
Thanks a lot :)
  2 comentarios
Image Analyst
Image Analyst el 24 de En. de 2021
You might get more answers if you attached your data so we had something to work with and give you once we've solved it. In the meantime, see my demo for scatteredInterpolant().
Ran Kagan
Ran Kagan el 24 de En. de 2021
Editada: Ran Kagan el 24 de En. de 2021
Attached.
BTW, for some reason, my code doesnt seem to work for the extreme cases, where, for instance, the user's input is theta_in = 0.

Iniciar sesión para comentar.

Respuestas (2)

Steven Lord
Steven Lord el 24 de En. de 2021
Is your data gridded or scattered? If it's gridded, scroll down to the "Interpolation with the interp Family of Functions" section on the page discussing interpolating gridded data linked from that "gridded or scattered" page.

Bjorn Gustavsson
Bjorn Gustavsson el 24 de En. de 2021
Have a look at the help and documentation for the functions interp2 and scatteredInterpolant. Either of those two functions will help you get this task solved. The first is preferable for the case where your independent variables r_sp and theta_sp are on a regular, plaid grid. Then everything is simple. If those variables are scattered then you will have to resort to scatteredInterpolant, that function handles that case.
HTH
  8 comentarios
Ran Kagan
Ran Kagan el 25 de En. de 2021
Editada: Ran Kagan el 25 de En. de 2021
Stupid me.
Of course it has this outlier, as I artifically put the values of 999 in order to find the 2nd most minimal value (see the code on my main question). This was before I knew that scatteredInterpolant deals with this issue in the background.
So I've deleted those funky lines, and now the scatter plot looks like so:
But the lines:
f_DOSE = scatteredInterpolant(r_sp(:),theta_sp(:),Dose_alpha_total(:),'linear');
DOSE_in = f_DOSE(r_in,theta_in);
Still dont give off good results, let alone for the extreme cases.. (and trisurf still gives the same error as before)
Bjorn Gustavsson
Bjorn Gustavsson el 25 de En. de 2021
Put a colour-bar on that scatter-plot, then plot the points you want to interpolate to:
colorbar
hold on
plot(r_i,theta_i,'r*')
If your interpolation-points are inside the "naturally coloured area then you should be able to do a natural sanity-check of the value you get for DOSE_in. In order to extend that value into the blue region you can always modify the limits of the colour-scale:
caxis([0 12]) % or whatever are a suitable lower and upper boundaries.

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation of 2-D Selections in 3-D Grids en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by