Filtering data from interpolated points on patch
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
The problem would be:
In the figure below, there are 6 points (xy) and the values (q) are assigned to these points. From these points, 3 triangles, colored by value, are drawn using the PATCH command.
By interpolating along two vertical lines I have determined 10-10 values. However, my problem is that it also interpolates values to places where there is no colored triangle (only white background).
Is there any way to zero out all the interpolated values that do not fall on the colored areas?
(This just demonstrates a simpler scenario, there are where I need to filter out these points for a model with many more triangles and white areas.)
The programme can be found below.
FIGURE:

PROGRAM:
xy = [1 3.1
2.6 2.8
1.3 1.9
2.8 1.5
3.7 2.1
2 0.9];
Connectivity_matrix = [3 2 1
5 2 4
6 4 3];
q = [1 2 3 1 2 3]';
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];
I = scatteredInterpolant(xy,q);
[x,y] = meshgrid([1.7; 2.4],linspace(0.8,3.2,10));
v = I(x,y)
figure ()
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',Connectivity_matrix,'Vertices', xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
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])
Do you have any idea how can I solve this problem?
Thank you so much for your helpful comments!
0 commentaires
Réponse acceptée
Voss
le 11 Mar 2024
xy = [1 3.1
2.6 2.8
1.3 1.9
2.8 1.5
3.7 2.1
2 0.9];
Connectivity_matrix = [3 2 1
5 2 4
6 4 3];
q = [1 2 3 1 2 3]';
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];
I = scatteredInterpolant(xy,q);
[x,y] = meshgrid([1.7; 2.4],linspace(0.8,3.2,10));
v = I(x,y)
% use inpolygon to say which points are in each triangle:
N_triangles = size(Connectivity_matrix,1);
in_triangle = false(numel(x),N_triangles);
for ii = 1:N_triangles
tri_xy = xy(Connectivity_matrix(ii,:),:);
in_triangle(:,ii) = inpolygon(x(:),y(:),tri_xy(:,1),tri_xy(:,2));
end
% a point is in a triangle if it is in any triangle:
in_triangle = any(in_triangle,2);
% zero out the interpolated values of points not in a triangle:
v(~in_triangle) = 0
figure ()
set(gcf, 'color', 'w')
colormap(RGB);
colorbar('EastOutside')
patch('Faces',Connectivity_matrix,'Vertices', xy,'FaceVertexCData',q,'FaceColor','interp')
axis equal
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])
% make texts and dots only at points in a triangle:
text(x(in_triangle),y(in_triangle),str(in_triangle),'HorizontalAlignment','right','BackgroundColor','w')
line(x(in_triangle),y(in_triangle),'LineStyle','none','Marker','o','Color',[0.75 0 0.75],'MarkerFaceColor',[0.75 0 0.75])
4 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multirate Signal Processing 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!

