![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189214/image.png)
How can I plot in 2D space the projection of area satisfied by inequalities in 3D space and also colour the area as a colour gradient with respect to the values of the Z variable?
1 次查看(过去 30 天)
显示 更早的评论
x+2y+4z > -20 ; x+z < -2.5 ; 2y+3z <-17 ;
I have the above inequalities and I need to plot the area satisfied by these inequalities in 2D space. Then I need to have the area coloured in a gradient which will correspond to the z values. Any idea how to do this? I want a figure similar to the one I have attached. Thanks!
0 个评论
采纳的回答
Sam Cook
2018-6-13
You could create a scatter plot of points that satisfy your equations, and color them based on the Z values.
range = -5:0.02:5;
lr = length(range);
[X, Y, Z] = meshgrid(range, range, range); % Points to check
ineq1 = X + 2*Y + 4*Z > -20; % Define the inequalities
ineq2 = X + Z < -2.5;
ineq3 = 2*Y + 3*Z < -17;
conditions = ineq1 & ineq2 & ineq3;
nX = X(conditions); % Get the points that satisfy them
nY = Y(conditions);
nZ = Z(conditions);
scatter(nX, nY, 10, nZ, 'filled'); % Plot the points, colored according to Z values
colorbar
grid on
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189214/image.png)
Because the equations produce 3D surfaces (rather than lines in 3D space), you
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!