Reputation: 99
x and y axis correspond to two dimensional arrays with (x,y). I want to mark all the points depending on some function which return boolean value.
f(xAxis_array, yAxis_array) returns True/False. If it's true, I wanna mark the point with red, black if otherwise.
For example, I want to get something similar as a result:
Thank you in advance!
Upvotes: 1
Views: 108
Reputation: 104484
That's pretty easy. You can split up the data into two portions - one portion that satisfies the constraint, and one portion that doesn't. You can then call plot
with the two portions and colour each point differently. Therefore, given your two arrays, xAxis_array
, and yAxis_array
, and given your function f
(assuming vectorized), you can do something like this:
ind = f(xAxis_array, yAxis_array);
redx = xAxis_array(ind);
redy = yAxis_array(ind);
blackx = xAxis_array(~ind);
blacky = yAxis_array(~ind);
plot(redx, redy, 'r.', blackx, blacky, 'k.');
The first line of code returns True/False
for each pair of points in xAxis_array
, and yAxis_array
. This would be a logical
vector that gives you whether or not the corresponding point is True
or False
. Once that's done, we use logical indexing to separate out the points that should be marked as red, and those that should be marked as black. Once you separate these out, we use a single plot
call so that those coordinates that are supposed to be red are marked in that colour and those that are black are marked as such.
Upvotes: 1