Effacer les filtres
Effacer les filtres

conditionally removing rows dependent on values of other rows

2 vues (au cours des 30 derniers jours)
K
K le 2 Oct 2015
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.

Réponse acceptée

Mohammad Abouali
Mohammad Abouali le 2 Oct 2015
Modifié(e) : Mohammad Abouali le 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 commentaires
K
K le 4 Oct 2015
Thank you! This worked very well.
Mohammad Abouali
Mohammad Abouali le 5 Oct 2015
You are welcome. If this concludes your question, would you please mark the answer as "accepted".

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by