如何在表面的脊上绘制点?

how to plot dot on the ridges of a surface?

我找不到在我的表面的下脊和上脊上绘制一些点的方法。 我为表面写了这段代码:


%initialize parameters
x   = linspace(-2,2,100);
y   = linspace(-2,2,80);
fxy = abs(log(x'.*y));


% it looks like this 
figure(1), clf
surf(x,y,fxy')
shading interp
axis square, rotate3d on
xlabel('X'), ylabel('y'), zlabel('f(x,y)')

为了找到下脊,我写了如下内容:

% find min

minval = min(min(fxy));
[xi,yi] = find( minval == fxy);


idx = sub2ind(size(fxy),xi,yi);

% plot the minimum as a red ball
hold on
plot3(x(xi),y(yi),fxy(idx)','ro', 'MarkerFaceColor','r','MarkerSize',12 )

然后对于下界(下脊)我设置了一个阈值 0.1 然后:


% finding lower ridge : points below a threshold of .01

[xi,yi] = find( fxy < minval+.01);

% to get the values,  convert from matrix indices to linear indices
idx = sub2ind(size(fxy),xi,yi);

% plot the close-to minimum points
plot3(x(xi),y(yi),fxy(idx)','ro','markerfacecolor','r','markersize',12)

现在我最多这样做了:

% finding maximum
maxval = max(max(fxy));
[xi,yi] = find( maxval == fxy);
% plot the maximum as a red ball
plot3(x(xi),y(yi),fxy(xi,yi)','ro', 'MarkerFaceColor','r','MarkerSize',12 )

现在我怎样才能找到上脊?我设置阈值5为上限,结果是这样的:

% finding upper ridge : points below a threshold of 5

[xi,yi] = find( maxval- fxy <5);

% to get the values,  convert from matrix indices to linear indices
idx = sub2ind(size(fxy),xi,yi);

% plot the close-to minimum points
plot3(x(xi),y(yi),fxy(idx)','ro','markerfacecolor','r','markersize',12)


哪个是仅获得上脊的最佳阈值?有没有其他方法可以只在上边缘绘制点?

对于顶部脊线,在一般情况下,我会遵循 Adriaan 的评论并查看导数(您可以为此使用函数 gradient)。

然而,在您的情况下,还有另一种方法,由于以下事实而成为可能:

  • 在您的表面 fxy 的任何 X 切片上,脊线 y 坐标将与此 X 切片的最大值重合。
  • 而且,在你表面的任何 Y 切片上 fxy,脊线 x 坐标将与此 Y 切片的最大值重合。

有了这个观察,max 函数就是您所需要的:

% Find maximum Z value and index for
[zxmax,idxzx] = max(fxy) ;          % All X slices (columns)
[zymax,idxzy] = max(fxy,[],2) ;     % All Y slices (rows)

xr = x(idxzx) ; % get the actual X coordinates from the column indices
yr = y(idxzy) ; % get the actual Y coordinates from the row indices

% Display
hold on
plot3(xr,y,zxmax,'r','LineWidth',4)
plot3(x,yr,zxmax,'b','LineWidth',4)

% Or if you want them dotted
% plot3(xr,y,zxmax,'or')
% plot3(x,yr,zymax,'ob')

这绘制在初始表面显示的顶部将呈现: