How to crop unwanted data from surfplot?

So I have a surf plot in which I'd like to extract two triangles from the bottom, as seen in the picture below.
Does anyone know how I might be able to do this?
My code can be seen below, just in case.
%load data
load("DATA")
X_data = DATA(:,1);
Y_data = DATA(:,2);
Sigma_data = DATA(:,3);
Rho_data = 1./DATA(:,3);
%create grid
[x,~,xi] = unique(X_data);
[y,~,yi] = unique(Y_data);
subs = [xi yi];%use the indices instead of values as coordinates
val = Rho_data;
val_sigma = Sigma_data;
M = accumarray(subs,val,[],[],NaN);%fill missing with NaN
N = accumarray(subs,val_sigma,[],[],NaN);%fill missing with NaN
[X,Y]=ndgrid(x,y); %generate the grid surf() expects
%create plot
figure(1),clf(1)
surf(X, Y, M); hold on
title('Perfil de Resistividad')
axis equal;
xlim([0 200]);
ylim([0 30]);
set(gca, 'YDir','reverse')
xticks(0:5:200)
yticks(0:5:200)
view(0,90),xlabel('Distancia en Perfil [m]'),ylabel('Profundidad [m]'), zlabel('Resistividad')
set(gca,'ColorScale','log', 'layer', 'top')
caxis([0.1 1000])
b = colorbar('southoutside', 'Ticks',[0.1, 0.5, 1, 3, 5, 10, 25, 50, 100, 200, 400, 600]);
b.Label.String = 'Resistividad [\Omega *m]';
%b.Label.Rotation = 270;
%b.Label.Position(1) = 3;
shading interp
%colormap('jet')
%change axis scale% set(gca,'ZScale','log')
%change colormap scale%
colormap(flipud(jet))

2 comentarios

Walter Roberson
Walter Roberson el 14 de Mzo. de 2022
That cannot be 60 degrees. 60 degrees is sides in the ratio 1:sqrt(3):2 but your triangle ratio is 30:22.5:something which is 4:3:something which is less than 50 degrees.
Camilo Vega García
Camilo Vega García el 14 de Mzo. de 2022
It's just for a vague reference. Sorry for the low quality drawing I made. I think my question still gets across even with the quality of the drawing.
In that case the question would be, how do I extract a triangular section of my surf plot given certain coordinates.

Iniciar sesión para comentar.

Respuestas (2)

KSSV
KSSV el 14 de Mzo. de 2022

0 votos

You should be having vertices of the triangle or your required region. USe inpolygon to get the indices of the coordinates which lie inside this region. Read about inpolygon.
Walter Roberson
Walter Roberson el 14 de Mzo. de 2022

0 votos

how do I extract a triangular section of my surf plot given certain coordinates.
Simple trig. Or use polyfit() and polyval() to determine boundary coordinates.
You can fill the data with NaN if you want transparency there. Or you can create a mask to use as AlphaData on a solid-color overlay if you want to block the area off.

2 comentarios

Camilo Vega García
Camilo Vega García el 16 de Mzo. de 2022
Could you elaborate a bit? I thought polyfitt was used to find the best polynomial function to fit to a point data.
p1 = [1 7]
p1 = 1×2
1 7
p2 = [5 0]
p2 = 1×2
5 0
x = [p1(1), p2(1)]
x = 1×2
1 5
y = [p1(2), p2(2)]
y = 1×2
7 0
plot(x, y, '-o')
P = polyfit(x, y, 1)
P = 1×2
-1.7500 8.7500
xinterp = 1:p2(1)
xinterp = 1×5
1 2 3 4 5
yinterp = polyval(P, xinterp)
yinterp = 1×5
7.0000 5.2500 3.5000 1.7500 0
hold on
scatter(xinterp, yinterp, '+')
So at x = xinterp(1), the upper boundary is yinterp(1) and you can nan fill M(1:yinterp(1), xinterp(1))
At x = xinterp(2), the upper boundary is yinterp(2) and you can nan fill M(1:yinterp(2), xinterp(2)) . And so on.
The logic for the other side is not much different.

Iniciar sesión para comentar.

Categorías

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

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 14 de Mzo. de 2022

Comentada:

el 16 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by