Surface plot positive output and corresponding combination of variables only

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.

 Réponse acceptée

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 commentaires

That works for me, but what if I have another function 2y-3x and the combination of the variables need to return positive output for both of the function, i.e. plot only surface that overlay each other. I know the hold function can plot both surface in same graph.
mask = F<0 | G<0;
F(mask) = nan;
G(mask) = nan;
Thanks for the help guys.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by