Interpolation to arbitrary points on a patch plot

조회 수: 10 (최근 30일)
Kovacs Mario
Kovacs Mario 2024년 3월 8일
댓글: Voss 2024년 3월 9일
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!

채택된 답변

Voss
Voss 2024년 3월 8일
편집: Voss 2024년 3월 8일
%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
Kovacs Mario
Kovacs Mario 2024년 3월 9일
Thank you!
Voss
Voss 2024년 3월 9일
You're welcome!

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

추가 답변 (1개)

Matt J
Matt J 2024년 3월 8일
편집: Matt J 2024년 3월 8일
For example,
F=scatteredInterpolant(msh_1.xy, q);
interpolatedValues = F({[0.68,1.87],0:0.2:1})
  댓글 수: 1
Kovacs Mario
Kovacs Mario 2024년 3월 8일
Thank you so much for your answer! :)
It was helpful too!

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

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by