How can we fill a region defined by a implicit function?

조회 수: 10 (최근 30일)
Maxim Bogdan
Maxim Bogdan 2021년 4월 17일
댓글: Star Strider 2021년 4월 17일
I use fimplicit(f, -10,10,-10,10) to plot the curve where . How can I color the region in which from the rectangle ?
I know a solution which is not that precise:
f=@(x,y) sin(x)*sin(y)-0.5;
x=linspace(a1,b1,100);
y=linspace(a2,b2,100);
[X,Y]=meshgrid(x,y);
condition=f(X,Y)>=0;
output=zeros(Nx,Ny);
output(~(condition))=1;
imshow(output, 'xdata', x, 'ydata', y);
axis on;
I don't know why the y-axis is reversed in that situation,and it appears smaller or greater depending on the length of x and y. Moreover I don't know how to use other colors than black and white (see here https://www.mathworks.com/matlabcentral/answers/297554-how-can-i-plot-the-region-for-two-inequalities). Anyway, is there a solution which maybe use the points we get from fimplicit?
fp=fimplicit(f,-10,10,-10,10);
Points=[fp.Xdata;fp.Ydata];
Maybe using patch or fill commands...? It works fine with patch if I have a connected curve, but this is not the case.
In Wolfram Alpha I just write f(x,y)>0 and the region is ploted. I wonder if there is such a code for Matlab too.
  댓글 수: 2
Maxim Bogdan
Maxim Bogdan 2021년 4월 17일
Thanks a lot!
That is what I mean.
Star Strider
Star Strider 2021년 4월 17일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 4월 17일
편집: Star Strider 2021년 4월 17일
I am not certain what you want.
Try this:
f=@(x,y) sin(x).*sin(y)-0.5;
figure
fp1=fimplicit(f,[-10,10,-10,10]);
hold on
fp2=fcontour(f,[0,10,0,10]);
fp2.LevelList = [0 0];
fp2.Fill = 'on';
colormap([1 1 1; 0 1 0])
hold off
.
EDIT — (17 Apr 2021 at 19:43)
Another option:
f=@(x,y) sin(x).*sin(y)-0.5;
figure
fp1=fimplicit(f,[-10,10,-10,10]);
hold on
fp2=fcontour(f,[0,10,0,10]);
fp2.LevelList = linspace(0, 0.5, 25);
hold off
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by