MATLAB: Approximation of e using random points

ifloopplotvectorizationvectorized codevectorizing

I have plotted one random thousand points on an axis. I have also plotted a line y=1/x. Now I am trying to display the points below the line in blue and the points above the line in orange. I have tried using an if loop but have not been successful. Any ideas how I could do this? Thanks

Best Answer

Hi Austin,
I have not tested the following code, so it may not be 100 percent correct, but it should give you the basic idea. I am assuming that you have two variables x and y, each one is a 1000 x 1 array of numbers:
idx = (y < 1./x);
figure;
scatter(x(idx),y(idx),'markerfacecolor','blue');
hold on;
scatter(x(~idx),y(~idx),'markerfacecolor','red');
HTH.
Rick