need to write values on contour plots

2 views (last 30 days)
danish ansari
danish ansari on 13 Oct 2020
Answered: Sudhakar Shinde on 13 Oct 2020
i want to write the objective function value on the contours.
which functiona should i use?
as of now i am using this
---% part of a code--
fcontour(f)
hold on;
plot(x,y,'*-r');
it is giving a following contour lines with different colours which are the values of function "f". so how can i print the values of function in these lines (not red lines).
while f is the function of x &y.

Answers (2)

Star Strider
Star Strider on 13 Oct 2020

Sudhakar Shinde
Sudhakar Shinde on 13 Oct 2020
these examples may help you:
%1
f = @(x,y) exp(-(x/3).^2-(y/3).^2) + exp(-(x+2).^2-(y+2).^2);
fc = fcontour(f);
fc.LineWidth = 1;
fc.LineStyle = '--';
fc.LevelList = [1 0.9 0.8 0.2 0.1];
colorbar
%2
figure
fcontour(@(x,y) x.*sin(y) - y.*cos(x), [-2*pi 2*pi], 'LineWidth', 2);
grid on
title({'xsin(y) - ycos(x)','-2\pi < x < 2\pi and -2\pi < y < 2\pi'})
xlabel('x')
ylabel('y')

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!