conditionally removing rows dependent on values of other rows

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 2 de Oct. de 2015
Editada: Mohammad Abouali el 2 de Oct. de 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 comentarios
K
K el 4 de Oct. de 2015
Thank you! This worked very well.
Mohammad Abouali
Mohammad Abouali el 5 de Oct. de 2015
You are welcome. If this concludes your question, would you please mark the answer as "accepted".

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by