conditionally removing rows dependent on values of other rows

1 view (last 30 days)
I have a set of points in a matrix that will be plotted as points in a x,y such it ends up looking like:
A:
2 0
3 0
4 0
2 1
3 1
4 1
...
2 8
3 8
4 8
...
(except with much more data)
giving a plot resembling:
y
| x x x x x x x x x x x
| x x x x x x x x x x x
| x x x x x x x x x x x
| x x x x x x x x x x x
| x x x x x x x x x x x
| x x x x x x x x x x x
| x x x x x x x x x x x
------------------------- x
I am trying to set boundary conditions such that I eliminate all the values outside a-x < y < a+x, where a is a constant, so that I can end up with something like this:
y
| x x x
| x x x x
| x x x x
| x x x x
| x x x x
| x x x x
| x x x x
------------------------- x
I would also like to restrict the values that x can be in order to isolate a specific region of points, then count how many I have left while being able to see it visually on a plot.
I have tried writing a few conditions, such as A(A(:,1)>A(:,2))=[], and even putting it in a loop, but it doesn't seem to work how I would like it to.
Any suggestions would be appreciated. I am still very green in terms of programming.

Accepted Answer

Mohammad Abouali
Mohammad Abouali on 2 Oct 2015
Edited: Mohammad Abouali on 2 Oct 2015
[x,y]=ndgrid(1:10);
A=[x(:) y(:)];
a=3;
mask = ((x-a)<y) & (y<(a+x));
plot(A(mask,1),A(mask,2),'x','MarkerSize',15,'LineWidth',2)
  2 Comments
Mohammad Abouali
Mohammad Abouali on 5 Oct 2015
You are welcome. If this concludes your question, would you please mark the answer as "accepted".

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements 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!