How to plot function with conditions (3d)

15 Ansichten (letzte 30 Tage)
Niklas Kurz
Niklas Kurz am 6 Dez. 2020
Kommentiert: Niklas Kurz am 6 Dez. 2020
Suppose I want to plot the function
% f(x,y) = x.*y by saying:
[x,y] = meshgrid (-2:2:2);
z = x.*y;
surf(x,y,z)
But what if I want the x and y values also to fulfill the equation x + y <= 1 ?

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 6 Dez. 2020
You can replace the unwanted values with nan.
[x,y] = meshgrid (-2:2:2);
z = x.*y;
mask = x + y <= 1;
z(~mask) = nan;
surf(x,y,z)

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by