Interpolation to arbitrary points on a patch plot

Hi,
My question is, if I have all my points on the plane and each point is assigned a specific value, how can I retrieve the values interpolated to an arbitrary point in the colored figure below?
(Perhaps better understood by running the program below after the problem I posed.)
A practical concrete example of this is shown in the PATCH figure below. If I select 2 vertical lines and enter the coordinates of 5 points equally spaced on the lines, how can I retrieve the interpolated values at those purple points?
THE PROGRAM:
%Values of points
q = [0;2.00997512422418;2.11482859825566;0;...
1.50960259671213;1.00498756211209;1.47648230602334];
RGB = [0 0 1
0 0.5 1
0 1 1
0 1 0.5
0 1 0
0.5 1 0
1 1 0
1 0.5 0
1 0 0];
% data for patch (connectivity matrices)
msh_1.nn_tria = [3,2,7;2,6,7;5,3,7;6,5,7];
msh_1.nn_quad = [5,4,1,6];
msh_1.xy = [0,0;2,0;2,1;0,1;1,1;1,0;1.5,0.5];
%% Visualisation with patch
figure (8)
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_tria,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
patch('Faces',msh_1.nn_quad,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
FIGURE:
Do you have any idea how can I solve this problem?
Thank you so much for your helpful comments!

 Réponse acceptée

Voss
Voss le 8 Mar 2024
Modifié(e) : Voss le 8 Mar 2024
%Values of points
q = [0;2.00997512422418;2.11482859825566;0;...
1.50960259671213;1.00498756211209;1.47648230602334];
RGB = [0 0 1
0 0.5 1
0 1 1
0 1 0.5
0 1 0
0.5 1 0
1 1 0
1 0.5 0
1 0 0];
% data for patch (connectivity matrices)
msh_1.nn_tria = [3,2,7;2,6,7;5,3,7;6,5,7];
msh_1.nn_quad = [5,4,1,6];
msh_1.xy = [0,0;2,0;2,1;0,1;1,1;1,0;1.5,0.5];
%% Visualisation with patch
figure()
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_tria,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
patch('Faces',msh_1.nn_quad,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
% interpolate q at msh_1.xy to the required points
I = scatteredInterpolant(msh_1.xy,q);
[x,y] = meshgrid([0.68; 1.87],linspace(0,1,5));
v = I(x,y)
v = 5×2
0.6834 1.8793 0.6834 1.8838 0.7742 1.9101 0.9004 1.9363 1.0265 2.0361
% visualization of interpolated values
str = compose('%.3f ',v);
text(x(:),y(:),str(:),'HorizontalAlignment','right','BackgroundColor','w')
line(x(:),y(:),'LineStyle','none','Marker','o','Color',[0.75 0 0.75],'MarkerFaceColor',[0.75 0 0.75])
% visualization of original (q) values, for comparison
figure()
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',msh_1.nn_tria,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
patch('Faces',msh_1.nn_quad,'Vertices', msh_1.xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
str = compose('%.3f ',q);
text(msh_1.xy(:,1),msh_1.xy(:,2),str(:),'HorizontalAlignment','right','BackgroundColor','w')
line(msh_1.xy(:,1),msh_1.xy(:,2),'LineStyle','none','Marker','x','Color','k')

4 commentaires

but the other respondent's method is similar to yours, but his gave slightly different numbers.
These were his lines:
F=scatteredInterpolant(msh_1.xy, q);
interpolatedValues = F({[0.68,1.87],0:0.2:1})
What do you think is the reason for this difference?
linspace(0,1,5)
ans = 1x5
0 0.2500 0.5000 0.7500 1.0000
0:0.2:1
ans = 1x6
0 0.2000 0.4000 0.6000 0.8000 1.0000
Thank you!
Voss
Voss le 9 Mar 2024
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 8 Mar 2024
Modifié(e) : Matt J le 8 Mar 2024
For example,
F=scatteredInterpolant(msh_1.xy, q);
interpolatedValues = F({[0.68,1.87],0:0.2:1})

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Produits

Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by