Finding smaller and larger values than user's input for 2D interpolation
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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:?
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 commentaires
Image Analyst
le 24 Jan 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().
Réponses (2)
Steven Lord
le 24 Jan 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.
0 commentaires
Bjorn Gustavsson
le 24 Jan 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 commentaires
Bjorn Gustavsson
le 25 Jan 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.
Voir également
Catégories
En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!