How to plot function with conditions (3d)

1 vue (au cours des 30 derniers jours)
Niklas Kurz
Niklas Kurz le 6 Déc 2020
Commenté : Niklas Kurz le 6 Déc 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 ?

Réponse acceptée

Ameer Hamza
Ameer Hamza le 6 Déc 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)

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by