Matlab 等值线图和非等值线图在一起

Matlab 等值线图和非等值线图在一起,matlab,plot,Matlab,Plot,我是matlab新手,我想用两个不等式绘制一个轮廓图,但我不知道如何绘制。我想要绘制轮廓图的函数是这样的: Z = (X-2).^2 + (Y-1).^2; 这是两个不等式: ineq1 = X.^2 - Y <= 2; ineq2 = X + Y <= 2; ineq1=X.^2-Y如果要在等高线图上绘制不等式的边界,可以使用 交叉点区域的着色有点棘手,我不确定这是否正是你想要做的,但你可以考虑使用,比如 % Indexes of x_vect, y_ineq1 and y_i

我是matlab新手,我想用两个不等式绘制一个轮廓图,但我不知道如何绘制。我想要绘制轮廓图的函数是这样的:

Z = (X-2).^2 + (Y-1).^2;
这是两个不等式:

ineq1 = X.^2 - Y <= 2;
ineq2 = X + Y <= 2;

ineq1=X.^2-Y如果要在等高线图上绘制不等式的边界,可以使用

交叉点区域的着色有点棘手,我不确定这是否正是你想要做的,但你可以考虑使用,比如

% Indexes of x_vect, y_ineq1 and y_ineq2 for region where both satisfied:
region_indexes = find(y_ineq1<y_ineq2);
region_indexes_rev = region_indexes(end:-1:1);

% To plot this area need to enclose it 
% (forward along y_ineq1 then back along y_ineq2)
patch([x_vect(region_indexes),x_vect(region_indexes_rev)],...
      [y_ineq1(region_indexes),y_ineq2(region_indexes_rev)],...
      [1 0.8 1]) % <- Color as [r g b]

% May or may not need following line depending on MATLAB version to set the yaxes
ylim([-4 4])

% Get the original plot over the top
hold on
[C,h] = contour(X,Y,Z);
clabel(C,h)
hold off
%x\u向量、y\u ineq1和y\u ineq2的索引,用于满足以下条件的区域:

region_indexes=find(y_IneQ1我看不出
hold on;plot();hold off;
?我真的不知道。让我把输出贴在这里,为什么图像错了?我不明白,我通过wolframalpha绘制了两个不等式,它是这样的(^2+-+y+%3C%3D+2+%2C+X+%2B+y+%3C%3D+2%3B),我希望轮廓图中有这样一个形状。谢谢你的回答。第一个代码只运行fisne,但当我尝试运行第二个代码时,matlab给了我:未定义的函数或变量“索引”。很抱歉,我以为我已经先检查了它。现在应该可以更好地工作了。
[X,Y] = meshgrid(-4:.2:4,-4:.2:4);
Z = (X-2).^2 + (Y-1).^2;

[C,h] = contour(X,Y,Z);
clabel(C,h)

x_vect = (-4:.05:4);
y_ineq1 = x_vect.^2 - 2;
y_ineq2 = 2 - x_vect;
line(x_vect, y_ineq1);
line(x_vect, y_ineq2);
% Indexes of x_vect, y_ineq1 and y_ineq2 for region where both satisfied:
region_indexes = find(y_ineq1<y_ineq2);
region_indexes_rev = region_indexes(end:-1:1);

% To plot this area need to enclose it 
% (forward along y_ineq1 then back along y_ineq2)
patch([x_vect(region_indexes),x_vect(region_indexes_rev)],...
      [y_ineq1(region_indexes),y_ineq2(region_indexes_rev)],...
      [1 0.8 1]) % <- Color as [r g b]

% May or may not need following line depending on MATLAB version to set the yaxes
ylim([-4 4])

% Get the original plot over the top
hold on
[C,h] = contour(X,Y,Z);
clabel(C,h)
hold off