Contour line plot corresponding to sharpest changes

2 次查看(过去 30 天)
Please refer the contour plot. The contour shows sharp changes of values along 2 vertically varying lines. I want to get the values of those lines and would like to draw dotted lines along those 2 lines of sharpest changes. Please help.
  1 个评论
Nathan Hardenberg
Nathan Hardenberg 2023-9-19
Maybe there is a better way, but this is an idea I had. You are not able to plot a line, but you plot points with high gradient instead.
% create example
x = -1:0.2:1;
y = x;
[X,Y] = meshgrid(x,y);
Z = heaviside(X - Y*0.5 + (Y+1).^2.*0.1) + rand(size(X))*0.06;
figure(1);
surf(X,Y,Z,'FaceColor','interp'); view(3) % plot example
gradientZ = abs(gradient(Z)); % calculate gradient (aka: how "sharp" the surface is)
figure(2);
surf(X,Y,gradientZ,'FaceColor','interp')
sharp = gradientZ > 0.3 % value for fine tuning | select only "sharp" changes
sharp = 11×11 logical array
0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0
% plot "sharp" points on the contour
figure(3); hold on;
contourf(X,Y,Z)
scatter(X(sharp), Y(sharp),'*','r','LineWidth',2)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by