Search code examples
matlabmatlab-figure

Matlab, fimplicit, how to show a specified region on graph using an inequality


I am using the fimplicit command to produce a graph, but I have a condition x+y<=1, and I want only that region of the graph to be shown.

Example: f = @(x,y) x.^2 + y.^2 - 3; fimplicit(f,[-3 3 -2 2])

If there is no such option within fimplicit, I am also open for the suggestions to modify the figure after plotting fimplicit. PS. Of course, my function is not the one above, it is much complicated, so I thought it would be useful to use a simple example here in this post. By the way, simply changing -3 and -2 to 0 and 3 and 2 to 1 won't work on my original function. Alternatively, what will work with my case is to paint the graph to white for the parts that I do not what to be visible such as x+y>=1, but I do not know how to do.


Solution

  • if instead of anonymous function handle you use a usual function handle, you will have more control over the output values of that function. Create this function in a separate .m file:

    function val = fun(x, y)
        val = x.^2 + y.^2 - 3;  
        val(x+y>1) = NaN;
    end
    

    and call it like that:

    fimplicit(@fun, [-3 3 -2 2])