Surface plot positive output and corresponding combination of variables only

4 次查看(过去 30 天)
I have a function with two variables over a range and wish to find all possible combination of the variables that will return positive output (>0).
Say the function is 2x-3y, and x and y is defined as
length_L = 0.0001:0.0001:0.005;
length_R = 0.0001:0.0001:0.005;
and all combinations of length_L and length_R is apply to the function by
[X, Y] = meshgrid(length_L, length_R);
F = 2*X-3Y;
which will return a matrix F which is the result of all combination of length_L and length_R, which can be visualize with
surf(length_L, length_R, F)
% or
surf(X, Y, F)
However, I only want to show the positive F value and the combination of two variables that will result it.
I had tried some logical indexing that I am certain are incorrect like
posF = F(F>0);
posX = X(F>0);
posY = Y(F>0);
surf(posX, posY, posF)
But does not work at all as posF, posX and posY are all vector and surf(X, Y, Z) the Z need to be in matrix.

采纳的回答

Cris LaPierre
Cris LaPierre 2020-12-28
What about setting the F values that are <=0 to NaN?
length_L = 0.0001:0.0001:0.005;
length_R = 0.0001:0.0001:0.005;
[X, Y] = meshgrid(length_L, length_R);
F = 2*X-3*Y;
F(F<=0) = nan;
surf(X, Y, F)
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by