need to write values on contour plots

2 ビュー (過去 30 日間)
danish ansari
danish ansari 2020 年 10 月 13 日
回答済み: Sudhakar Shinde 2020 年 10 月 13 日
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.

回答 (2 件)

Star Strider
Star Strider 2020 年 10 月 13 日

Sudhakar Shinde
Sudhakar Shinde 2020 年 10 月 13 日
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')

カテゴリ

Help Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by