Surface plot positive output and corresponding combination of variables only
4 views (last 30 days)
Show older comments
Kai Jie See
on 28 Dec 2020
Commented: Kai Jie See
on 29 Dec 2020
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.
0 Comments
Accepted Answer
Cris LaPierre
on 28 Dec 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!