Making a 2D plot of an equation against 2 datasets
Afficher commentaires plus anciens
Hello,
I am trying to make a 2D plot of x and y based on a certain relation between them
Let:
x= 1:1:20
y= 1:0.5:8
Now, I want to plot z= x*y against x and y in the xy plane. Also, I only want to see the values of z such that z <10 or any other range .
Can someone please tell me how to do this? It seems simple, but I’m not a MATLAB Wiz.
Regards,
Réponses (2)
x = 1:1:20;
y = 1:0.5:8;
[X,Y] = meshgrid(x,y);
Z = X.*Y;
surf(X,Y,Z)
zlim([0 10]);
You could also replace the last two lines by something like
scatter3(X(Z<10),Y(Z<10),Z(Z<10),[],Z(Z<10))
2 commentaires
Kyle
le 19 Sep 2018
Like this?
scatter(X(Z<10),Y(Z<10),[],Z(Z<10))
or
Z(Z>=10)=NaN;
imagesc(X(:),Y(:),Z)
or
Z(Z>=10)=NaN;
contourf(X,Y,Z)
Star Strider
le 19 Sep 2018
Modifié(e) : Star Strider
le 19 Sep 2018
For a 2D version, try this:
x = 1:1:20;
y = 1:0.5:8;
z = bsxfun(@times, x, y');
z(z >= 10) = NaN;
figure
plot(z)
grid
Using contour with specific labeled levels:
x = 1:1:20;
y = 1:0.5:8;
[X,Y] = ndgrid(x,y);
Z = X.*Y;
figure
[C,h] = contour(X, Y, Z, 1:0.5:10);
Lvls = h.LevelList;
h.LevelList = Lvls(Lvls < 10);
clabel(C, h, Lvls(1:2:end))
xlabel('X')
ylabel('Y')
Catégories
En savoir plus sur Axis Labels dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!