Generating empty interval of points

Dear All,
I want to generate points in the interval [20,80] and have the interval [40,60] as an empty area. I wrote this code but I don't now how to complete it. I'd appreciate any help.
LB=20;UB=80;
x = LB+(UB-LB)*rand(50,1);
y =LB+(UB-LB)*rand(50,1);
if x>40 | x<60| y>40 | y<60;
[x]==0;[y]==0;
plot(x,y, '.')
but it gives an error.
Regards

 Respuesta aceptada

Star Strider
Star Strider el 14 de En. de 2015
This seems to work:
LB=20;UB=80;
x = LB+(UB-LB)*rand(50,1);
y = LB+(UB-LB)*rand(50,1);
idx = [((x > 40) & (x < 60)) | ((y > 40) & (y < 60))];
x(idx) = [];
y(idx) = [];
figure(1)
plot(x, y, '+')
grid
The ‘idx’ variable tests for the conditions and creates a logical vector then used to assign the elements of ‘x’ and ‘y’ to ‘empty’ rather than zero. The plot shows that there are no points in the area you want cleared.

5 comentarios

imola
imola el 14 de En. de 2015
Dear Star,
Thanks for you and for Roger for answer me, I realize that I didn't explain what I want exactly, forgave me both of you, with your code I got four areas of points separate of each other while I need a whole area of points and an empty area in the middle, is like an empty square inside a big square of points, so I tried to use
t = ((x<=40)||(x>=60)) && ((y<=40)||(y>=60));
but its wrong, could you please sorted to me.
Regards,
Imola.
Star Strider
Star Strider el 14 de En. de 2015
Editada: Star Strider el 14 de En. de 2015
@imola — Change only the ‘idx’ line in my code to:
idx = [((x > 40) & (x < 60)) & ((y > 40) & (y < 60))];
to get this plot:
Image Analyst
Image Analyst el 14 de En. de 2015
That does give an empty square in the 40-60 range. It relies on tossing out points that initially landed in there, so that the final number of points is most likely less than 50. Do you need exactly 50 points in there, or is it okay to get however many you end up with?
imola
imola el 15 de En. de 2015
Thanks Star, that's fine, it works perfectly .
Regards
Star Strider
Star Strider el 15 de En. de 2015
My pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Roger Stafford
Roger Stafford el 14 de En. de 2015
Do this:
LB=20;UB=80;
x = LB+(UB-LB)*rand(50,1);
y = LB+(UB-LB)*rand(50,1);
t = ((x<=40)|(x>=60)) & ((y<=40)|(y>=60));
x = x(t);
y = y(t);
plot(x,y,'.')

1 comentario

imola
imola el 14 de En. de 2015
Dear Roger, Thanks for you and for star for answer me, I realize that I didn't explain what I want exactly, forgave me both of you, with your code I got four areas of points separate of each other while I need a whole area of points and an empty area in the middle, is like an empty square inside a big square of points, so I tried to use
t = ((x<=40)||(x>=60)) && ((y<=40)||(y>=60));
but its wrong, could you please sorted to me.
Regards,
Imola.

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de En. de 2015

Comentada:

el 15 de En. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by