Filter löschen
Filter löschen

conditionally removing rows dependent on values of other rows

2 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by