How to crop unwanted data from surfplot?
Show older comments
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 Comments
Walter Roberson
on 14 Mar 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
on 14 Mar 2022
Answers (2)
KSSV
on 14 Mar 2022
0 votes
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
on 14 Mar 2022
0 votes
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 Comments
Camilo Vega García
on 16 Mar 2022
p1 = [1 7]
p2 = [5 0]
x = [p1(1), p2(1)]
y = [p1(2), p2(2)]
plot(x, y, '-o')
P = polyfit(x, y, 1)
xinterp = 1:p2(1)
yinterp = polyval(P, xinterp)
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.
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!