Contour line plot corresponding to sharpest changes
2 views (last 30 days)
Show older comments
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 Comment
Nathan Hardenberg
on 19 Sep 2023
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
% plot "sharp" points on the contour
figure(3); hold on;
contourf(X,Y,Z)
scatter(X(sharp), Y(sharp),'*','r','LineWidth',2)
Answers (0)
See Also
Categories
Find more on Contour Plots 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!