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

51 visualizaciones (últimos 30 días)
Maxim Bogdan
Maxim Bogdan el 17 de Abr. de 2021
Comentada: Star Strider el 17 de Abr. de 2021
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 comentarios
Maxim Bogdan
Maxim Bogdan el 17 de Abr. de 2021
Thanks a lot!
That is what I mean.
Star Strider
Star Strider el 17 de Abr. de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 17 de Abr. de 2021
Editada: Star Strider el 17 de Abr. de 2021
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
.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by