Matlab 如何在曲面的脊上绘制点?

Matlab 如何在曲面的脊上绘制点?,matlab,plot,min,Matlab,Plot,Min,我找不到办法在我的曲面上下脊上画一些点。 我为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

我找不到办法在我的曲面上下脊上画一些点。 我为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)

现在我怎么才能找到上山脊?我为upper设置了阈值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)


%查找上脊:低于阈值5的点

[xi,yi]=find(maxval-fxy对于顶脊,在一般情况下,我会跟随Adrian的评论并查看导数(您可以使用函数)

但是,在您的情况下,还有另一种方法,因为:

  • 在曲面的任何
    X
    切片上
    fxy
    ,脊
    y
    坐标将与该
    X
    切片的最大值一致
  • 并且,在曲面的任何
    Y
    切片上
    fxy
    ,脊
    x
    坐标将与该
    Y
    切片的最大值一致
有了这一观察,您所需要的功能就是:

% 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')
绘制在初始曲面显示顶部的此选项将渲染:


< /P>你想得到什么作为“上边缘”?你需要考虑的是,使用一个粗糙的、水平的阈值用于<代码> f(x,y)< /代码>将导致高于水平表面的所有点(在图像中大约<代码> z=3.2 < /代码>)被标记。如果你想要真正的边,这比应用一个简单的1D阈值要复杂得多。我想你需要用导数来识别那些边。我不知道你想做什么,但从数学上讲,因为没有“上脊”这样的东西.所以突出显示一个数字伪影是很奇怪的,太棒了!非常感谢你的直观回答,你知道,我不知道如何使用指示词来找到整个山脊。我知道导数可以给我最大值(最高点),但它怎么能给出沿着脊线的所有点呢?我应该使用二次方向还是什么?每次信号在Z方向变化时(分别从上到下或从下到上),导数都会改变符号(从正到负,或从负到正)。因为你的脊线就是这样(信号在Z方向上变化),您可以尝试查找导数为=0的点(指示方向变化)。由于域是离散的,您可能找不到导数正好为

0
的点,在这种情况下,您可以选择距离
0
最近的点(在具有不同符号的两个点之间)。
% 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')