How to assign 'null values' to certain ranges of an equation based on a criteria?
Show older comments
Hi guys,
I have two equations. I want one of those (Eq2) to only have valid values when Eq1 is yielding positive values. For all the negative values of Eq1 for given x,y, I want Eq2 to give null or invalid values.
Here's the sample:
x=[-10:10];
y=[-10:10];
Eq1 = @(x,y) x - y;
Eq2 = @(x,y) x + y;
[X,Y] = meshgrid(x,y);
Z1 = Eq1(X,Y);
Z2 = Eq2(X,Y);
Basically: I want Eq2 to have values for only those x,y where Eq1 is >= 0. For all x,y where Eq1 is < 0, I want Eq2 to have invalid/null values. So that when I go to graph Eq2 or just pull values from it, it only does it for areas where Eq1 is >= 0.
Is this possible?
Thank you
Accepted Answer
More Answers (1)
Guillaume
on 13 Jul 2015
There's no concept of null values in matrices, but you have NaN (Not a Number) instead.
Z1 = Eq1(X, Y);
Z2 = Eq2(X, Y);
Z2(Z1 < 0) = NaN; %set values of Z2 where Z1 is < 0 to NaN.
Categories
Find more on Numeric Solvers 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!