conditionally removing rows dependent on values of other rows

1 次查看(过去 30 天)
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.

采纳的回答

Mohammad Abouali
Mohammad Abouali 2015-10-2
编辑:Mohammad Abouali 2015-10-2
[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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by